Search in sources :

Example 6 with Artifact

use of org.apache.maven.artifact.Artifact in project jetty.project by eclipse.

the class JettyRunForkedMojo method getExtraJars.

private Set<Artifact> getExtraJars() throws Exception {
    Set<Artifact> extraJars = new HashSet<Artifact>();
    List l = pluginArtifacts;
    Artifact pluginArtifact = null;
    if (l != null) {
        Iterator itor = l.iterator();
        while (itor.hasNext() && pluginArtifact == null) {
            Artifact a = (Artifact) itor.next();
            if (//get the jetty-maven-plugin jar
            a.getArtifactId().equals(plugin.getArtifactId())) {
                extraJars.add(a);
            }
        }
    }
    return extraJars;
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Artifact(org.apache.maven.artifact.Artifact) HashSet(java.util.HashSet)

Example 7 with Artifact

use of org.apache.maven.artifact.Artifact in project jetty.project by eclipse.

the class JettyRunMojo method configureWebApplication.

/** 
     * @see org.eclipse.jetty.maven.plugin.AbstractJettyMojo#configureWebApplication()
     */
public void configureWebApplication() throws Exception {
    super.configureWebApplication();
    //Set up the location of the webapp.
    //There are 2 parts to this: setWar() and setBaseResource(). On standalone jetty,
    //the former could be the location of a packed war, while the latter is the location
    //after any unpacking. With this mojo, you are running an unpacked, unassembled webapp,
    //so the two locations should be equal.
    Resource webAppSourceDirectoryResource = Resource.newResource(webAppSourceDirectory.getCanonicalPath());
    if (webApp.getWar() == null)
        webApp.setWar(webAppSourceDirectoryResource.toString());
    if (webApp.getBaseResource() == null)
        webApp.setBaseResource(webAppSourceDirectoryResource);
    if (classesDirectory != null)
        webApp.setClasses(classesDirectory);
    if (useTestScope && (testClassesDirectory != null))
        webApp.setTestClasses(testClassesDirectory);
    webApp.setWebInfLib(getDependencyFiles());
    //get copy of a list of war artifacts
    Set<Artifact> matchedWarArtifacts = new HashSet<Artifact>();
    //process any overlays and the war type artifacts
    List<Overlay> overlays = new ArrayList<Overlay>();
    for (OverlayConfig config : warPluginInfo.getMavenWarOverlayConfigs()) {
        //overlays can be individually skipped
        if (config.isSkip())
            continue;
        //an empty overlay refers to the current project - important for ordering
        if (config.isCurrentProject()) {
            Overlay overlay = new Overlay(config, null);
            overlays.add(overlay);
            continue;
        }
        //if a war matches an overlay config
        Artifact a = getArtifactForOverlay(config, getWarArtifacts());
        if (a != null) {
            matchedWarArtifacts.add(a);
            SelectiveJarResource r = new SelectiveJarResource(new URL("jar:" + Resource.toURL(a.getFile()).toString() + "!/"));
            r.setIncludes(config.getIncludes());
            r.setExcludes(config.getExcludes());
            Overlay overlay = new Overlay(config, r);
            overlays.add(overlay);
        }
    }
    //iterate over the left over war artifacts and unpack them (without include/exclude processing) as necessary
    for (Artifact a : getWarArtifacts()) {
        if (!matchedWarArtifacts.contains(a)) {
            Overlay overlay = new Overlay(null, Resource.newResource(new URL("jar:" + Resource.toURL(a.getFile()).toString() + "!/")));
            overlays.add(overlay);
        }
    }
    webApp.setOverlays(overlays);
    //if we have not already set web.xml location, need to set one up
    if (webApp.getDescriptor() == null) {
        //Has an explicit web.xml file been configured to use?
        if (webXml != null) {
            Resource r = Resource.newResource(webXml);
            if (r.exists() && !r.isDirectory()) {
                webApp.setDescriptor(r.toString());
            }
        }
        //Still don't have a web.xml file: try the resourceBase of the webapp, if it is set
        if (webApp.getDescriptor() == null && webApp.getBaseResource() != null) {
            Resource r = webApp.getBaseResource().addPath("WEB-INF/web.xml");
            if (r.exists() && !r.isDirectory()) {
                webApp.setDescriptor(r.toString());
            }
        }
        //Still don't have a web.xml file: finally try the configured static resource directory if there is one
        if (webApp.getDescriptor() == null && (webAppSourceDirectory != null)) {
            File f = new File(new File(webAppSourceDirectory, "WEB-INF"), "web.xml");
            if (f.exists() && f.isFile()) {
                webApp.setDescriptor(f.getCanonicalPath());
            }
        }
    }
    getLog().info("web.xml file = " + webApp.getDescriptor());
    getLog().info("Webapp directory = " + webAppSourceDirectory.getCanonicalPath());
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) ArrayList(java.util.ArrayList) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) URL(java.net.URL) HashSet(java.util.HashSet)

Example 8 with Artifact

use of org.apache.maven.artifact.Artifact in project jetty.project by eclipse.

the class JettyRunMojo method gatherScannables.

public void gatherScannables() throws Exception {
    if (webApp.getDescriptor() != null) {
        Resource r = Resource.newResource(webApp.getDescriptor());
        scanner.watch(r.getFile().toPath());
    }
    if (webApp.getJettyEnvXml() != null)
        scanner.watch(new File(webApp.getJettyEnvXml()).toPath());
    if (webApp.getDefaultsDescriptor() != null) {
        if (!WebAppContext.WEB_DEFAULTS_XML.equals(webApp.getDefaultsDescriptor()))
            scanner.watch(new File(webApp.getDefaultsDescriptor()).toPath());
    }
    if (webApp.getOverrideDescriptor() != null) {
        scanner.watch(new File(webApp.getOverrideDescriptor()).toPath());
    }
    File jettyWebXmlFile = findJettyWebXmlFile(new File(webAppSourceDirectory, "WEB-INF"));
    if (jettyWebXmlFile != null) {
        scanner.watch(jettyWebXmlFile.toPath());
    }
    //make sure each of the war artifacts is added to the scanner
    for (Artifact a : getWarArtifacts()) {
        scanner.watch(a.getFile().toPath());
    }
    //handle the explicit extra scan targets
    if (scanTargets != null) {
        for (File f : scanTargets) {
            if (f.isDirectory()) {
                PathWatcher.Config config = new PathWatcher.Config(f.toPath());
                config.setRecurseDepth(PathWatcher.Config.UNLIMITED_DEPTH);
                scanner.watch(config);
            } else
                scanner.watch(f.toPath());
        }
    }
    //handle the extra scan patterns
    if (scanTargetPatterns != null) {
        for (ScanTargetPattern p : scanTargetPatterns) {
            PathWatcher.Config config = new PathWatcher.Config(p.getDirectory().toPath());
            config.setRecurseDepth(PathWatcher.Config.UNLIMITED_DEPTH);
            for (String pattern : p.getExcludes()) config.addExcludeGlobRelative(pattern);
            for (String pattern : p.getIncludes()) config.addIncludeGlobRelative(pattern);
            scanner.watch(config);
        }
    }
    scanner.watch(project.getFile().toPath());
    if (webApp.getTestClasses() != null && webApp.getTestClasses().exists()) {
        PathWatcher.Config config = new PathWatcher.Config(webApp.getTestClasses().toPath());
        config.setRecurseDepth(PathWatcher.Config.UNLIMITED_DEPTH);
        if (scanTestClassesPattern != null) {
            for (String p : scanTestClassesPattern.getExcludes()) config.addExcludeGlobRelative(p);
            for (String p : scanTestClassesPattern.getIncludes()) config.addIncludeGlobRelative(p);
        }
        scanner.watch(config);
    }
    if (webApp.getClasses() != null && webApp.getClasses().exists()) {
        PathWatcher.Config config = new PathWatcher.Config(webApp.getClasses().toPath());
        config.setRecurseDepth(PathWatcher.Config.UNLIMITED_DEPTH);
        if (scanClassesPattern != null) {
            for (String p : scanClassesPattern.getExcludes()) config.addExcludeGlobRelative(p);
            for (String p : scanClassesPattern.getIncludes()) config.addIncludeGlobRelative(p);
        }
        scanner.watch(config);
    }
    if (webApp.getWebInfLib() != null) {
        for (File f : webApp.getWebInfLib()) {
            PathWatcher.Config config = new PathWatcher.Config(f.toPath());
            config.setRecurseDepth(PathWatcher.Config.UNLIMITED_DEPTH);
            scanner.watch(config);
        }
    }
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) PathWatcher(org.eclipse.jetty.util.PathWatcher) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 9 with Artifact

use of org.apache.maven.artifact.Artifact in project semantic-versioning by jeluard.

the class AbstractEnforcerRule method execute.

@Override
public void execute(final EnforcerRuleHelper helper) throws EnforcerRuleException {
    final MavenProject project = getMavenProject(helper);
    if (shouldSkipRuleExecution(project)) {
        helper.getLog().debug("Skipping non " + AbstractEnforcerRule.JAR_ARTIFACT_TYPE + " or " + BUNDLE_ARTIFACT_TYPE + " artifact.");
        return;
    }
    final Artifact previousArtifact;
    final Artifact currentArtifact = validateArtifact(project.getArtifact());
    final Version current = Version.parse(currentArtifact.getVersion());
    try {
        final ArtifactRepository localRepository = (ArtifactRepository) helper.evaluate("${localRepository}");
        final String version;
        if (this.previousVersion != null) {
            version = this.previousVersion;
            helper.getLog().info("Version specified as <" + version + ">");
        } else {
            final ArtifactMetadataSource artifactMetadataSource = (ArtifactMetadataSource) helper.getComponent(ArtifactMetadataSource.class);
            final List<ArtifactVersion> availableVersions = getAvailableReleasedVersions(artifactMetadataSource, project, localRepository);
            final List<ArtifactVersion> availablePreviousVersions = filterNonPreviousVersions(availableVersions, current);
            if (availablePreviousVersions.isEmpty()) {
                helper.getLog().warn("No previously released version. Backward compatibility check not performed.");
                return;
            }
            version = availablePreviousVersions.iterator().next().toString();
            helper.getLog().info("Version deduced as <" + version + "> (among all availables: " + availablePreviousVersions + ")");
        }
        final ArtifactFactory artifactFactory = (ArtifactFactory) helper.getComponent(ArtifactFactory.class);
        previousArtifact = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), version, null, project.getArtifact().getType());
        final ArtifactResolver resolver = (ArtifactResolver) helper.getComponent(ArtifactResolver.class);
        resolver.resolve(previousArtifact, project.getRemoteArtifactRepositories(), localRepository);
        validateArtifact(previousArtifact);
    } catch (Exception e) {
        helper.getLog().warn("Exception while accessing artifacts; skipping check.", e);
        return;
    }
    final Version previous = Version.parse(previousArtifact.getVersion());
    final File previousJar = previousArtifact.getFile();
    final File currentJar = currentArtifact.getFile();
    compareJars(helper, previous, previousJar, current, currentJar);
}
Also used : DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) MavenProject(org.apache.maven.project.MavenProject) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) Version(org.semver.Version) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) ArtifactMetadataSource(org.apache.maven.artifact.metadata.ArtifactMetadataSource) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) ArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver) ExpressionEvaluationException(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException) IOException(java.io.IOException) EnforcerRuleException(org.apache.maven.enforcer.rule.api.EnforcerRuleException) ArtifactMetadataRetrievalException(org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException)

Example 10 with Artifact

use of org.apache.maven.artifact.Artifact in project randomizedtesting by randomizedtesting.

the class JUnit4Mojo method setupTestClasspath.

/**
   * Setup the classpath used for tests.
   */
private void setupTestClasspath(Element junit4) {
    junit4.addComment("Runtime classpath.");
    Element cp = junit4.addElement("classpath");
    // Test classes.
    cp.addComment("Test classes directory.");
    cp.addElement("pathelement").addAttribute("location", testClassesDirectory.getAbsolutePath());
    // Classes directory.
    cp.addComment("Test classes directory.");
    cp.addElement("pathelement").addAttribute("location", classesDirectory.getAbsolutePath());
    // Project dependencies.
    cp.addComment("Project dependencies.");
    Set<Artifact> classpathArtifacts = (Set<Artifact>) project.getArtifacts();
    if (!Strings.isNullOrEmpty(classpathDependencyScopeExclude)) {
        classpathArtifacts = filterArtifacts(cp, classpathArtifacts, new ScopeArtifactFilter(classpathDependencyScopeExclude));
    }
    if (classpathDependencyExcludes != null && !classpathDependencyExcludes.isEmpty()) {
        classpathArtifacts = filterArtifacts(cp, classpathArtifacts, new PatternIncludesArtifactFilter(classpathDependencyExcludes));
    }
    for (Artifact artifact : classpathArtifacts) {
        if (artifact.getArtifactHandler().isAddedToClasspath()) {
            File file = artifact.getFile();
            if (file != null) {
                cp.addComment("Dependency artifact: " + artifact.getId());
                cp.addElement("pathelement").addAttribute("location", file.getAbsolutePath());
            }
        }
    }
    // Additional dependencies.
    cp.addComment("Additional classpath elements.");
    if (additionalClasspathElements != null && !additionalClasspathElements.isEmpty()) {
        for (String classpathElement : additionalClasspathElements) {
            if (!Strings.isNullOrEmpty(classpathElement)) {
                cp.addElement("pathelement").addAttribute("location", classpathElement);
            }
        }
    }
}
Also used : ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Element(org.dom4j.Element) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

Artifact (org.apache.maven.artifact.Artifact)450 File (java.io.File)175 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)92 ArrayList (java.util.ArrayList)91 MavenProject (org.apache.maven.project.MavenProject)63 IOException (java.io.IOException)50 HashSet (java.util.HashSet)42 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)32 LinkedHashSet (java.util.LinkedHashSet)29 MojoFailureException (org.apache.maven.plugin.MojoFailureException)24 HashMap (java.util.HashMap)22 Set (java.util.Set)22 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)22 ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)21 URL (java.net.URL)20 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)20 Test (org.junit.Test)20 MalformedURLException (java.net.MalformedURLException)18 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)17 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)16