Example usage for org.apache.maven.project MavenProject getPackaging

List of usage examples for org.apache.maven.project MavenProject getPackaging

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getPackaging.

Prototype

public String getPackaging() 

Source Link

Usage

From source file:org.apache.felix.obrplugin.ObrDeployFile.java

License:Apache License

public void execute() throws MojoExecutionException {
    MavenProject project = getProject();
    String projectType = project.getPackaging();

    // ignore unsupported project types, useful when bundleplugin is configured in parent pom
    if (!supportedProjectTypes.contains(projectType)) {
        getLog().warn(//from   ww w . j av  a  2  s . com
                "Ignoring project type " + projectType + " - supportedProjectTypes = " + supportedProjectTypes);
        return;
    } else if ("NONE".equalsIgnoreCase(remoteOBR) || "false".equalsIgnoreCase(remoteOBR)) {
        getLog().info("Remote OBR update disabled (enable with -DremoteOBR)");
        return;
    }

    // if the user doesn't supply an explicit name for the remote OBR file, use the local name instead
    if (null == remoteOBR || remoteOBR.trim().length() == 0 || "true".equalsIgnoreCase(remoteOBR)) {
        remoteOBR = obrRepository;
    }

    URI tempURI = ObrUtils.findRepositoryXml("", remoteOBR);
    String repositoryName = new File(tempURI.getSchemeSpecificPart()).getName();

    Log log = getLog();
    ObrUpdate update;

    RemoteFileManager remoteFile = new RemoteFileManager(m_wagonManager, settings, log);
    remoteFile.connect(repositoryId, url);

    // ======== LOCK REMOTE OBR ========
    log.info("LOCK " + remoteFile + '/' + repositoryName);
    remoteFile.lockFile(repositoryName, ignoreLock);
    File downloadedRepositoryXml = null;

    try {
        // ======== DOWNLOAD REMOTE OBR ========
        log.info("Downloading " + repositoryName);
        downloadedRepositoryXml = remoteFile.get(repositoryName, ".xml");

        String mavenRepository = localRepository.getBasedir();

        URI repositoryXml = downloadedRepositoryXml.toURI();
        URI obrXmlFile = ObrUtils.toFileURI(obrXml);
        URI bundleJar;

        if (null == file) {
            bundleJar = ObrUtils.getArtifactURI(localRepository, project.getArtifact());
        } else {
            bundleJar = file.toURI();
        }

        Config userConfig = new Config();
        userConfig.setRemoteFile(true);

        if (null != bundleUrl) {
            // public URL differs from the bundle file location
            URI uri = URI.create(bundleUrl);
            log.info("Computed bundle uri: " + uri);
            userConfig.setRemoteBundle(uri);
        } else if (null != file) {
            // assume file will be deployed in remote repository, so find the remote relative location
            URI uri = URI.create(localRepository.pathOf(project.getArtifact()));
            log.info("Computed bundle uri: " + uri);
            userConfig.setRemoteBundle(uri);
        }

        update = new ObrUpdate(repositoryXml, obrXmlFile, project, mavenRepository, userConfig, log);
        update.parseRepositoryXml();

        update.updateRepository(bundleJar, null, null);

        update.writeRepositoryXml();

        if (downloadedRepositoryXml.exists()) {
            // ======== UPLOAD MODIFIED OBR ========
            log.info("Uploading " + repositoryName);
            remoteFile.put(downloadedRepositoryXml, repositoryName);
        }
    } catch (Exception e) {
        log.warn("Exception while updating remote OBR: " + e.getLocalizedMessage(), e);
    } finally {
        // ======== UNLOCK REMOTE OBR ========
        log.info("UNLOCK " + remoteFile + '/' + repositoryName);
        remoteFile.unlockFile(repositoryName);
        remoteFile.disconnect();

        if (null != downloadedRepositoryXml) {
            downloadedRepositoryXml.delete();
        }
    }
}

From source file:org.apache.felix.obrplugin.ObrInstallFile.java

License:Apache License

public void execute() throws MojoExecutionException {
    MavenProject project = getProject();
    String projectType = project.getPackaging();

    // ignore unsupported project types, useful when bundleplugin is configured in parent pom
    if (!supportedProjectTypes.contains(projectType)) {
        getLog().warn(// w  w w . j a  v a  2s.  com
                "Ignoring project type " + projectType + " - supportedProjectTypes = " + supportedProjectTypes);
        return;
    } else if ("NONE".equalsIgnoreCase(obrRepository) || "false".equalsIgnoreCase(obrRepository)) {
        getLog().info("Local OBR update disabled (enable with -DobrRepository)");
        return;
    }

    Log log = getLog();
    ObrUpdate update;

    String mavenRepository = localRepository.getBasedir();

    URI repositoryXml = ObrUtils.findRepositoryXml(mavenRepository, obrRepository);
    URI obrXmlFile = ObrUtils.toFileURI(obrXml);
    URI bundleJar;

    if (null == file) {
        bundleJar = ObrUtils.getArtifactURI(localRepository, project.getArtifact());
    } else {
        bundleJar = file.toURI();
    }

    Config userConfig = new Config();

    update = new ObrUpdate(repositoryXml, obrXmlFile, project, mavenRepository, userConfig, log);
    update.parseRepositoryXml();

    update.updateRepository(bundleJar, null, null);

    update.writeRepositoryXml();
}

From source file:org.apache.sling.maven.slingstart.DependencyLifecycleParticipant.java

License:Apache License

@Override
public void afterProjectsRead(final MavenSession session) throws MavenExecutionException {
    final Environment env = new Environment();
    env.artifactHandlerManager = artifactHandlerManager;
    env.resolver = resolver;/*from  ww  w . ja v a2 s  . c o m*/
    env.logger = logger;
    env.session = session;

    logger.debug("Searching for " + BuildConstants.PACKAGING_SLINGSTART + "/"
            + BuildConstants.PACKAGING_PARTIAL_SYSTEM + " projects...");

    for (final MavenProject project : session.getProjects()) {
        if (project.getPackaging().equals(BuildConstants.PACKAGING_SLINGSTART)
                || project.getPackaging().equals(BuildConstants.PACKAGING_PARTIAL_SYSTEM)) {
            logger.debug("Found " + project.getPackaging() + " project: " + project);
            // search plugin configuration (optional)
            final ProjectInfo info = new ProjectInfo();
            for (Plugin plugin : project.getBuild().getPlugins()) {
                if (plugin.getArtifactId().equals(PLUGIN_ID)) {
                    info.plugin = plugin;
                    break;
                }
            }
            info.project = project;
            env.modelProjects.put(project.getGroupId() + ":" + project.getArtifactId(), info);
        }
    }

    new ModelPreprocessor().addDependencies(env);
}

From source file:org.apache.tuscany.maven.plugin.eclipse.EclipsePlugin.java

License:Apache License

/**
 * If this is a war module peek into the reactor an search for an ear module that defines the context root of this
 * module./*ww w.j av  a 2  s  .c  o  m*/
 *
 * @param config config to save the context root.
 */
private void collectWarContextRootsFromReactorEarConfiguration(EclipseWriterConfig config) {
    if (reactorProjects != null && wtpContextName == null
            && Constants.PROJECT_PACKAGING_WAR.equals(project.getPackaging())) {
        for (Iterator iter = reactorProjects.iterator(); iter.hasNext();) {
            MavenProject reactorProject = (MavenProject) iter.next();

            if (Constants.PROJECT_PACKAGING_EAR.equals(reactorProject.getPackaging())) {
                Xpp3Dom[] warDefinitions = IdeUtils.getPluginConfigurationDom(reactorProject,
                        JeeUtils.ARTIFACT_MAVEN_EAR_PLUGIN, new String[] { "modules", "webModule" });
                for (int index = 0; index < warDefinitions.length; index++) {
                    Xpp3Dom groupId = warDefinitions[index].getChild("groupId");
                    Xpp3Dom artifactId = warDefinitions[index].getChild("artifactId");
                    Xpp3Dom contextRoot = warDefinitions[index].getChild("contextRoot");
                    if (groupId != null && artifactId != null && contextRoot != null
                            && groupId.getValue() != null && artifactId.getValue() != null
                            && contextRoot.getValue() != null) {
                        getLog().info("Found context root definition for " + groupId.getValue() + ":"
                                + artifactId.getValue() + " " + contextRoot.getValue());
                        if (project.getArtifactId().equals(artifactId.getValue())
                                && project.getGroupId().equals(groupId.getValue())) {
                            config.setContextName(contextRoot.getValue());
                        }
                    } else {
                        getLog().info("Found incomplete ear configuration in " + reactorProject.getGroupId()
                                + ":" + reactorProject.getGroupId() + " found "
                                + warDefinitions[index].toString());
                    }
                }
            }
        }
    }
    if (config.getContextName() == null && Constants.PROJECT_PACKAGING_WAR.equals(project.getPackaging())) {
        if (wtpContextName == null) {
            config.setContextName(project.getArtifactId());
        } else {
            config.setContextName(wtpContextName);
        }
    }
}

From source file:org.codehaus.cargo.maven2.util.CargoProject.java

License:Apache License

/**
 * Saves all attributes./*from   w w w . ja  v a 2 s  .  c  o m*/
 * @param project Maven2 project.
 * @param log Logger.
 */
public CargoProject(MavenProject project, Log log) {
    this(project.getPackaging(), project.getGroupId(), project.getArtifactId(),
            project.getBuild().getDirectory(), project.getBuild().getFinalName(), project.getArtifact(),
            project.getAttachedArtifacts(), project.getArtifacts(), log);
}

From source file:org.codehaus.mojo.cobertura.CoberturaReportMojo.java

License:Apache License

/**
 * Test if the project has pom packaging
 *
 * @param mavenProject Project to test//from w w  w  . j a  v  a2s  .c  o m
 * @return True if it has a pom packaging
 */
private boolean isMultiModule(MavenProject mavenProject) {
    return "pom".equals(mavenProject.getPackaging());
}

From source file:org.codehaus.mojo.freeform.analyser.Analyser.java

License:Apache License

/**
 * This method gives the <packaging>Analyser associated to the mavenProject
 * packaging. The returned Analyser is injected withe the given parameters.
 *
 * @param mavenProject    The maven project which defines the packaging.
 * @param executedProject The maven prokect resulting of the phases
 *                        prerequisites.
 * @param localRepository The local repository of the Maven2 execution.
 * @param log             The logging system.
 * @param mavenpath       The path to the maven executable.
 * @return the <packaging>Analyser which is the one defined for the
 *         packaging of the given mavenProject.
 *///from  w  w  w. j a v a 2s  . c o  m
public static Analyser getAnalyser(final MavenProject mavenProject, final MavenProject executedProject,
        final ArtifactRepository localRepository, final Log log, final String mavenpath) {
    Analyser analyser = null;

    // choose the <packaging>Analyser for the given project.
    if ((mavenProject.getPackaging() != null) && mavenProject.getPackaging().equalsIgnoreCase("jar")) {
        analyser = new JarAnalyser();
    } else if ((mavenProject.getPackaging() != null)
            && mavenProject.getPackaging().equalsIgnoreCase("maven-plugin")) {
        analyser = new MavenPluginAnalyser();
    } else {
        analyser = new JarAnalyser();
    }

    // inject the mavenProject, the executedProject, the localRepository,
    // the log, and the maven path to the choosen analyser.
    analyser.setMavenProject(mavenProject);
    analyser.setMavenExecutedProject(executedProject);
    analyser.setLocalRepository(localRepository);
    analyser.setLog(log);
    analyser.setMavenPath(mavenpath);

    log.info(analyser + " found");

    return analyser;
}

From source file:org.codehaus.mojo.jdiff.JDiffUtils.java

License:Apache License

public static List<String> getProjectSourceRoots(MavenProject p, List<String> compileSourceRoots) {
    if ("pom".equals(p.getPackaging().toLowerCase())) {
        return Collections.emptyList();
    }//from   w  w  w . j  av a2 s.  c  om
    return (compileSourceRoots == null ? Collections.<String>emptyList()
            : new LinkedList<String>(compileSourceRoots));
}

From source file:org.codehaus.mojo.nbm.CreateClusterMojo.java

License:Apache License

public void execute() throws MojoExecutionException, MojoFailureException {
    Project antProject = registerNbmAntTasks();

    if (!nbmBuildDir.exists()) {
        nbmBuildDir.mkdirs();/*from ww w .ja v a2s .c o m*/
    }

    if (reactorProjects != null && reactorProjects.size() > 0) {
        for (MavenProject proj : reactorProjects) {
            //TODO how to figure where the the buildDir/nbm directory is
            File nbmDir = new File(proj.getBasedir(),
                    "target" + File.separator + "nbm" + File.separator + "netbeans");
            if (nbmDir.exists()) {
                Copy copyTask = (Copy) antProject.createTask("copy");
                copyTask.setTodir(nbmBuildDir);
                copyTask.setOverwrite(true);
                FileSet set = new FileSet();
                set.setDir(nbmDir);
                set.createInclude().setName("**");
                copyTask.addFileset(set);

                try {
                    copyTask.execute();
                } catch (BuildException ex) {
                    getLog().error("Cannot merge modules into cluster");
                    throw new MojoExecutionException("Cannot merge modules into cluster", ex);
                }
            } else {
                if ("nbm".equals(proj.getPackaging())) {
                    String error = "The NetBeans binary directory structure for " + proj.getId()
                            + " is not created yet."
                            + "\n Please execute 'mvn install nbm:cluster' to build all relevant projects in the reactor.";
                    throw new MojoFailureException(error);
                }
                if ("bundle".equals(proj.getPackaging())) {
                    Artifact art = proj.getArtifact();
                    final ExamineManifest mnf = new ExamineManifest(getLog());

                    File jar = new File(proj.getBuild().getDirectory(),
                            proj.getBuild().getFinalName() + ".jar");
                    if (!jar.exists()) {
                        getLog().error("Skipping " + proj.getId()
                                + ". Cannot find the main artifact in output directory.");
                        continue;
                    }
                    mnf.setJarFile(jar);
                    mnf.checkFile();

                    File cluster = new File(nbmBuildDir, defaultCluster);
                    getLog().debug("Copying " + art.getId() + " to cluster " + defaultCluster);
                    File modules = new File(cluster, "modules");
                    modules.mkdirs();
                    File config = new File(cluster, "config");
                    File confModules = new File(config, "Modules");
                    confModules.mkdirs();
                    File updateTracting = new File(cluster, "update_tracking");
                    updateTracting.mkdirs();

                    final String cnb = mnf.getModule();
                    final String cnbDashed = cnb.replace(".", "-");
                    final File moduleArt = new File(modules, cnbDashed + ".jar"); //do we need the file in some canotical name pattern?
                    final String specVer = mnf.getSpecVersion();
                    try {
                        FileUtils.copyFile(jar, moduleArt);
                        final File moduleConf = new File(confModules, cnbDashed + ".xml");
                        FileUtils.copyStreamToFile(new InputStreamFacade() {
                            public InputStream getInputStream() throws IOException {
                                return new StringInputStream(CreateClusterAppMojo.createBundleConfigFile(cnb,
                                        mnf.isBundleAutoload()), "UTF-8");
                            }
                        }, moduleConf);
                        FileUtils.copyStreamToFile(new InputStreamFacade() {
                            public InputStream getInputStream() throws IOException {
                                return new StringInputStream(CreateClusterAppMojo.createBundleUpdateTracking(
                                        cnb, moduleArt, moduleConf, specVer), "UTF-8");
                            }
                        }, new File(updateTracting, cnbDashed + ".xml"));
                    } catch (IOException exc) {
                        getLog().error(exc);
                    }

                }
            }
        }
        //in 6.1 the rebuilt modules will be cached if the timestamp is not touched.
        File[] files = nbmBuildDir.listFiles();
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory()) {
                File stamp = new File(files[i], ".lastModified");
                if (!stamp.exists()) {
                    try {
                        stamp.createNewFile();
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                }
                stamp.setLastModified(new Date().getTime());
            }
        }
        getLog().info("Created NetBeans module cluster(s) at " + nbmBuildDir);
    } else {
        throw new MojoExecutionException("This goal only makes sense on reactor projects.");
    }
}

From source file:org.codehaus.mojo.pom.DependencyInfo.java

License:Apache License

/**
 * The constructor from a {@link MavenProject}.
 *///from   w  w  w . ja  v  a2s . co  m
public DependencyInfo(MavenProject project) {

    this(project.getGroupId(), project.getArtifactId(), project.getVersion(), project.getPackaging(), null,
            null);
}