Search in sources :

Example 11 with MavenProject

use of org.apache.maven.project.MavenProject in project yeoman-maven-plugin by trecloux.

the class YeomanMojoTest method test_should_skip_tests_when_flag_set.

public void test_should_skip_tests_when_flag_set() throws Exception {
    MavenProject project = getMavenProject("src/test/resources/test-mojo-default-pom.xml");
    YeomanMojo yeomanMojo = (YeomanMojo) lookupConfiguredMojo(project, "build");
    yeomanMojo.skipTests = true;
    List<String> commands = executeMojoAndCaptureCommands(yeomanMojo);
    assertThat(commands).containsExactly("node --version", "npm --version", "npm install", "bower --version", "bower install --no-color", "grunt --version", "grunt build --no-color");
}
Also used : MavenProject(org.apache.maven.project.MavenProject)

Example 12 with MavenProject

use of org.apache.maven.project.MavenProject in project flyway by flyway.

the class AbstractFlywayMojoSmallTest method skipExecute.

@Test
public void skipExecute() throws Exception {
    AbstractFlywayMojo mojo = new AbstractFlywayMojo() {

        @Override
        protected void doExecute(Flyway flyway) throws Exception {
            assertNull(flyway.getDataSource());
        }
    };
    mojo.skip = true;
    mojo.url = "jdbc:h2:mem:dummy";
    mojo.mavenProject = new MavenProject();
    mojo.execute();
}
Also used : Flyway(org.flywaydb.core.Flyway) MavenProject(org.apache.maven.project.MavenProject) Test(org.junit.Test)

Example 13 with MavenProject

use of org.apache.maven.project.MavenProject in project intellij-community by JetBrains.

the class MavenEmbedder method readProject.

@NotNull
private MavenExecutionResult readProject(@NotNull final MavenExecutionRequest request) {
    ProfileManager globalProfileManager = request.getGlobalProfileManager();
    globalProfileManager.loadSettingsProfiles(request.getSettings());
    MavenProject rootProject = null;
    final List<Exception> exceptions = new ArrayList<Exception>();
    Object result = null;
    try {
        final File pomFile = new File(request.getPomFile());
        if (!pomFile.exists()) {
            throw new FileNotFoundException("File doesn't exist: " + pomFile.getPath());
        }
        final Method getProjectsMethod = DefaultMaven.class.getDeclaredMethod("getProjects", MavenExecutionRequest.class);
        getProjectsMethod.setAccessible(true);
        Maven maven = getComponent(Maven.class);
        result = getProjectsMethod.invoke(maven, request);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        return handleException(e.getTargetException());
    } catch (Exception e) {
        return handleException(e);
    }
    if (result != null) {
        MavenProjectBuilder builder = getComponent(MavenProjectBuilder.class);
        for (Object p : (List) result) {
            MavenProject project = (MavenProject) p;
            try {
                builder.calculateConcreteState(project, request.getProjectBuilderConfiguration(), false);
            } catch (ModelInterpolationException e) {
                exceptions.add(e);
            }
            if (project.isExecutionRoot()) {
                rootProject = project;
            }
        }
        if (rootProject == null && exceptions.isEmpty()) {
            throw new RuntimeException("Could't build project for unknown reason");
        }
    }
    return new MavenExecutionResult(rootProject, exceptions);
}
Also used : DefaultProfileManager(org.apache.maven.profiles.DefaultProfileManager) ProfileManager(org.apache.maven.profiles.ProfileManager) DefaultMaven(org.apache.maven.DefaultMaven) Maven(org.apache.maven.Maven) FileNotFoundException(java.io.FileNotFoundException) Method(java.lang.reflect.Method) PlexusContainerException(org.codehaus.plexus.PlexusContainerException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) FileNotFoundException(java.io.FileNotFoundException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) SecDispatcherException(org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MavenProjectBuilder(org.apache.maven.project.MavenProjectBuilder) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) MavenProject(org.apache.maven.project.MavenProject) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with MavenProject

use of org.apache.maven.project.MavenProject in project jangaroo-tools by CoreMedia.

the class PackageApplicationMojo method getDependencies.

private List<String> getDependencies(Artifact artifact) throws ProjectBuildingException {
    MavenProject mp = mavenProjectBuilder.buildFromRepository(artifact, remoteRepositories, localRepository, true);
    List<String> deps = new LinkedList<String>();
    for (Dependency dep : getDependencies(mp)) {
        if ("jar".equals(dep.getType()) && (dep.getScope().equals("compile") || dep.getScope().equals("runtime"))) {
            deps.add(getInternalId(dep));
        }
    }
    return deps;
}
Also used : MavenProject(org.apache.maven.project.MavenProject) Dependency(org.apache.maven.model.Dependency) LinkedList(java.util.LinkedList)

Example 15 with MavenProject

use of org.apache.maven.project.MavenProject in project asterixdb by apache.

the class LicenseMojo method addDependencyToLicenseMap.

private void addDependencyToLicenseMap(MavenProject depProject, List<Pair<String, String>> depLicenses, String depLocation) {
    final String depGav = toGav(depProject);
    getLog().debug("adding " + depGav + ", location: " + depLocation);
    final MutableBoolean usedMetric = new MutableBoolean(false);
    if (depLicenses.size() > 1) {
        Collections.sort(depLicenses, (o1, o2) -> {
            final int metric1 = getLicenseMetric(o1.getLeft());
            final int metric2 = getLicenseMetric(o2.getLeft());
            usedMetric.setValue(usedMetric.booleanValue() || metric1 != LicenseSpec.UNDEFINED_LICENSE_METRIC || metric2 != LicenseSpec.UNDEFINED_LICENSE_METRIC);
            return Integer.compare(metric1, metric2);
        });
        if (usedMetric.booleanValue()) {
            getLog().info("Multiple licenses for " + depGav + ": " + depLicenses + "; taking lowest metric: " + depLicenses.get(0));
        } else {
            getLog().warn("Multiple licenses for " + depGav + ": " + depLicenses + "; taking first listed: " + depLicenses.get(0));
        }
    } else if (depLicenses.isEmpty()) {
        getLog().info("no license defined in model for " + depGav);
        depLicenses.add(new ImmutablePair<>("MISSING_LICENSE", null));
    }
    Pair<String, String> key = depLicenses.get(0);
    String licenseUrl = key.getLeft();
    final String displayName = key.getRight();
    if (!urlToLicenseMap.containsKey(licenseUrl)) {
        // assuming we've not already mapped it, annotate the URL with artifact info, if not an actual URL
        try {
            getLog().debug("- URL: " + new URL(licenseUrl));
        // life is good
        } catch (MalformedURLException e) {
            // we encounter this a lot.  Log a warning, and use an annotated key
            final String fakeLicenseUrl = depGav.replaceAll(":", "--") + "_" + licenseUrl;
            getLog().info("- URL for " + depGav + " is malformed: " + licenseUrl + "; using: " + fakeLicenseUrl);
            licenseUrl = fakeLicenseUrl;
        }
    }
    addProject(new Project(depProject, depLocation, depProject.getArtifact().getFile()), new LicenseSpec(licenseUrl, displayName), true);
}
Also used : Project(org.apache.hyracks.maven.license.project.Project) MavenProject(org.apache.maven.project.MavenProject) MalformedURLException(java.net.MalformedURLException) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) URL(java.net.URL)

Aggregations

MavenProject (org.apache.maven.project.MavenProject)291 File (java.io.File)134 ArrayList (java.util.ArrayList)63 Artifact (org.apache.maven.artifact.Artifact)63 Model (org.apache.maven.model.Model)57 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)36 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)32 Assembly (org.apache.maven.plugins.assembly.model.Assembly)28 IOException (java.io.IOException)27 EasyMockSupport (org.easymock.classextension.EasyMockSupport)27 ArtifactMock (org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock)20 HashSet (java.util.HashSet)16 DependencySet (org.apache.maven.plugins.assembly.model.DependencySet)16 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)16 HashMap (java.util.HashMap)15 LinkedHashSet (java.util.LinkedHashSet)15 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)15 MavenSession (org.apache.maven.execution.MavenSession)15 FileSet (org.apache.maven.plugins.assembly.model.FileSet)15 Logger (org.codehaus.plexus.logging.Logger)15