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.openspaces.maven.plugin.RunStandalonePUMojo.java

License:Apache License

/**
 * Prepares and executes the PU.//from  w  w  w. java2s  .  c om
 *
 * @throws MojoExecutionException
 * @throws MojoFailureException
 */
private void executePU(MavenProject project) throws MojoExecutionException, MojoFailureException {
    if (project == null || !project.getPackaging().equalsIgnoreCase("jar")) {
        throw new MojoExecutionException("The processing unit project '"
                + (project == null ? "unknown" : project.getName()) + "' must be of type jar (packaging=jar).");
    }

    // resolve the classpath for the execution of the processing unit
    List<URL> classpath;
    ClassLoader classLoader;
    try {
        String[] includeScopes = Utils.convertCommaSeparatedListToArray(scopes);
        classpath = Utils.resolveExecutionClasspath(project, includeScopes, false, reactorProjects,
                dependencyTreeBuilder, metadataSource, artifactCollector, artifactResolver, artifactFactory,
                localRepository, remoteRepositories);
        PluginLog.getLog().info("Processing unit [" + project.getName() + "] classpath: " + classpath);
        classLoader = Utils.createClassLoader(classpath, null);
    } catch (Exception e1) {
        throw new MojoExecutionException("Failed to resolve the processing unit's classpath", e1);
    }

    if (groups != null && !groups.trim().equals("")) {
        SystemInfo.singleton().lookup().setGroups(groups);
    }
    if (locators != null && !locators.trim().equals("")) {
        SystemInfo.singleton().lookup().setLocators(locators);
    }

    // run the PU
    PluginLog.getLog().info("Running processing unit: " + project.getBuild().getFinalName());

    ContainerRunnable conatinerRunnable = new ContainerRunnable(
            "org.openspaces.pu.container.standalone.StandaloneProcessingUnitContainer",
            createAttributesArray(Utils.getProcessingUnitJar((project))));
    Thread thread = new Thread(conatinerRunnable,
            "Processing Unit [" + project.getBuild().getFinalName() + "]");
    thread.setContextClassLoader(classLoader);
    thread.start();
    while (!conatinerRunnable.hasStarted()) {
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
        }
    }
    if (conatinerRunnable.getException() != null) {
        Utils.throwMissingLicenseException(conatinerRunnable.getException(), localRepository);
        throw new MojoExecutionException(
                "Failed to start processing unit [" + project.getBuild().getFinalName() + "]",
                conatinerRunnable.getException());
    }
    containers.add(thread);
}

From source file:org.openspaces.maven.plugin.Utils.java

License:Apache License

/**
 * Finds the relative path from current directory to the PU jar file.
 *
 * @param project the Maven project/*  ww w.  j a va  2 s.  c  o m*/
 * @return the relative path from current directory to the PU jar file.
 */
static String getProcessingUnitJar(MavenProject project) {
    String targetDir = project.getBuild().getDirectory();
    String curDir = System.getProperty("user.dir");
    String relativePath = targetDir.substring(curDir.length() + 1);
    relativePath = relativePath.replace('\\', '/');
    String finalName = project.getBuild().getFinalName();
    if ("war".equalsIgnoreCase(project.getPackaging())) {
        return relativePath + "/" + finalName + ".war";
    } else {
        return relativePath + "/" + finalName + ".jar";
    }
}

From source file:org.ops4j.pax.construct.clone.CloneMojo.java

License:Apache License

/**
 * {@inheritDoc}/*from   w w  w . j  a va 2s  . c  om*/
 */
public void execute() throws MojoExecutionException {
    // general purpose Pax-Construct script
    PaxScript buildScript = new PaxScriptImpl();

    m_bundleNameMap = new HashMap();
    m_majorProjectMap = new HashMap();
    m_handledDirs = new ArrayList();

    m_installCommands = new ArrayList();

    getFragmentDir().mkdirs();

    for (Iterator i = m_reactorProjects.iterator(); i.hasNext();) {
        // potential project to be converted / captured
        MavenProject project = (MavenProject) i.next();
        String packaging = project.getPackaging();

        // fixup standalone maven project
        if (m_reactorProjects.size() == 1) {
            // always repair
            repair = true;

            // provide basic jar conversion
            if ("jar".equals(packaging)) {
                packaging = "bundle";
            }
        }

        if ("bundle".equals(packaging)) {
            handleBundleProject(buildScript, project);
        } else if ("pom".equals(packaging)) {
            if (isMajorProject(project)) {
                handleMajorProject(buildScript, project);
            } else {
                handleBundleImport(buildScript, project);
            }
        }
        // else handled by the major project(s)
    }

    // grab everything else
    archiveMajorProjects();

    writePlatformScripts(buildScript);
}

From source file:org.ops4j.pax.construct.lifecycle.ProvisionMojo.java

License:Apache License

/**
 * Does this look like a provisioning POM? ie. artifactId of 'provision', packaging type 'pom', with dependencies
 * //from   www  .  ja v  a 2 s .c  o  m
 * @param project a Maven project
 * @return true if this looks like a provisioning POM, otherwise false
 */
public static boolean isProvisioningPom(MavenProject project) {
    // ignore POMs which don't have provision as their artifactId
    if (!"provision".equals(project.getArtifactId())) {
        return false;
    }

    // ignore POMs that produce actual artifacts
    if (!"pom".equals(project.getPackaging())) {
        return false;
    }

    // ignore POMs with no dependencies at all
    List dependencies = project.getDependencies();
    if (dependencies == null || dependencies.size() == 0) {
        return false;
    }

    return true;
}

From source file:org.ops4j.pax.construct.project.ImportBundleMojo.java

License:Apache License

/**
 * @param rootId initial import//from  w w  w  . j  a  va  2  s.c o m
 */
private void importBundles(String rootId) {
    while (!m_candidateIds.isEmpty()) {
        String id = (String) m_candidateIds.remove(0);
        String[] fields = id.split(":");

        MavenProject p = buildMavenProject(fields[0], fields[1], fields[2]);
        if (null == p) {
            continue;
        }

        if ("pom".equals(p.getPackaging())) {
            // support 'dependency' POMs
            processDependencies(p);
        } else if (rootId.equals(id) /* user knows best: assume given artifact is a bundle */
                || PomUtils.isBundleProject(p, m_resolver, m_remoteRepos, m_localRepo, testMetadata)) {
            importBundle(p);

            // stop at first bundle
            if (!importTransitive) {
                break;
            }

            processDependencies(p);
        } else {
            getLog().info("Ignoring non-bundle dependency " + p.getId());
        }
    }
}

From source file:org.ops4j.pax.construct.util.PomUtils.java

License:Apache License

/**
 * @param project Maven project/*from www .  j a  v  a 2s.co  m*/
 * @param resolver artifact resolver
 * @param remoteRepos sequence of remote repositories
 * @param localRepo local Maven repository
 * @param testMetadata check jar manifest for OSGi attributes if true
 * @return true if this is an OSGi bundle project, otherwise false
 */
public static boolean isBundleProject(MavenProject project, ArtifactResolver resolver, List remoteRepos,
        ArtifactRepository localRepo, boolean testMetadata) {
    String packaging = project.getPackaging();
    if (packaging != null && packaging.indexOf("bundle") >= 0) {
        return true;
    }

    return isBundleArtifact(project.getArtifact(), resolver, remoteRepos, localRepo, testMetadata);
}

From source file:org.owasp.dependencycheck.maven.AggregateMojo.java

License:Apache License

/**
 * Test if the project has pom packaging
 *
 * @param mavenProject Project to test/*from  w  w  w  .j a  v a 2 s.  c  o m*/
 * @return <code>true</code> if it has a pom packaging; otherwise
 * <code>false</code>
 */
protected boolean isMultiModule(MavenProject mavenProject) {
    return "pom".equals(mavenProject.getPackaging());
}

From source file:org.sonar.api.test.MavenTestUtils.java

License:Open Source License

public static MavenProject mockPom(String packaging) {
    MavenProject mavenProject = mock(MavenProject.class);
    when(mavenProject.getPackaging()).thenReturn(packaging);
    return mavenProject;
}

From source file:org.sonar.batch.MavenProjectBuilder.java

License:Open Source License

public Project create(MavenProject pom) {
    Configuration configuration = getStartupConfiguration(pom);
    return new Project(loadProjectKey(pom), loadProjectBranch(configuration), pom.getName()).setPom(pom)
            .setDescription(pom.getDescription()).setPackaging(pom.getPackaging());
}

From source file:org.sonar.batch.ProjectConfigurator.java

License:Open Source License

public Project create(ProjectDefinition definition) {
    Project project = new Project(definition.getKey(), loadProjectBranch(), definition.getName());

    // For backward compatibility we must set POM and actual packaging
    project.setDescription(StringUtils.defaultString(definition.getDescription()));
    project.setPackaging("jar");

    for (Object component : definition.getContainerExtensions()) {
        if (component instanceof MavenProject) {
            MavenProject pom = (MavenProject) component;
            project.setPom(pom);//  ww w.  j  a  v a 2  s .c o  m
            project.setPackaging(pom.getPackaging());
        }
    }
    return project;
}