List of usage examples for org.apache.maven.artifact.resolver.filter InversionArtifactFilter InversionArtifactFilter
public InversionArtifactFilter(ArtifactFilter toInvert)
From source file:npanday.plugin.compile.AbstractCompilerMojo.java
License:Apache License
protected void execute(boolean test) throws MojoExecutionException { long startTime = System.currentTimeMillis(); String scope = test ? "test" : "compile"; try {//from ww w . jav a2 s. co m AndArtifactFilter filter = new AndArtifactFilter(); filter.add(new ScopeArtifactFilter(scope)); filter.add(new InversionArtifactFilter(new DotnetSymbolsArtifactFilter())); dependencyResolution.require(project, LocalRepositoryUtil.create(localRepository), filter); } catch (ArtifactResolutionException e) { throw new MojoExecutionException( "NPANDAY-900-010: Could not satisfy required dependencies for scope " + scope, e); } //Modifies the AssemblyInfo.cs files to match the version of the pom try { updateAssemblyInfoVersion(); } catch (Exception e) { } initializeDefaults(); try { CompilerExecutable compilerExecutable = netExecutableFactory .getCompilerExecutable(getCompilerRequirement(), getCompilerConfig(), project); if (!compilerExecutable.shouldCompile()) { getLog().debug("NPANDAY-900-011: Compiler vetoed compile, see preceding log entries for details"); return; } File compiledArtifact = compilerExecutable.getCompiledArtifact(); // TODO: see issue with CompilerContextImpl.getArtifact(), which does not incorporate outputDirectory if (outputDirectory != null) { ArtifactType artifactType = getCompilerConfig().getArtifactType(); // TODO: shouldn't this use build.finalName? compiledArtifact = new File(outputDirectory.getAbsolutePath() + File.separator + project.getArtifactId() + "." + artifactType.getExtension()); } if (!test) { // System.Runtime.Versioning.TargetFrameworkAttribute support generateAssemblyAttributesIfNecessary(compilerExecutable.getTargetFramework()); Boolean sourceFilesUpToDate = (Boolean) super.getPluginContext().get("SOURCE_FILES_UP_TO_DATE"); if ((sourceFilesUpToDate != null && sourceFilesUpToDate) && System.getProperty("forceCompile") == null && compilerExecutable.getCompiledArtifact() != null && compilerExecutable.getCompiledArtifact().exists()) { if (isUpToDateWithPomAndSettingsAndDependencies(compilerExecutable.getCompiledArtifact())) { getLog().info("NPANDAY-900-003: Nothing to compile - all classes are up-to-date"); attachArtifact(compiledArtifact, classifier); return; } } } FileUtils.mkdir(project.getBuild().getDirectory()); long startTimeCompile = System.currentTimeMillis(); compilerExecutable.execute(); long endTimeCompile = System.currentTimeMillis(); getLog().info("NPANDAY-900-004: Compile Time = " + (endTimeCompile - startTimeCompile) + " ms"); if (!test) { attachArtifact(compiledArtifact, classifier); } } catch (PlatformUnsupportedException e) { throw new MojoExecutionException("NPANDAY-900-005: Unsupported Platform: Language = " + language + ", Vendor = " + vendor + ", ArtifactType = " + project.getArtifact().getType(), e); } catch (ExecutionException e) { throw new MojoExecutionException("NPANDAY-900-006: Unable to Compile: Language = " + language + ", Vendor = " + vendor + ", ArtifactType = " + project.getArtifact().getType() + ", Source Directory = " + project.getBuild().getSourceDirectory(), e); } long endTime = System.currentTimeMillis(); getLog().info("NPANDAY-900-013: Mojo Execution Time = " + (endTime - startTime)); }
From source file:npanday.plugin.compile.ComponentInitializerMojo.java
License:Apache License
public void execute() throws MojoExecutionException { // TODO: sadly we must resolve dependencies here because of 'org.apache.maven.plugins:maven-remote-resources-plugin:1.2.1:process' running later try {//from w w w.j a v a2s . c o m AndArtifactFilter filter = new AndArtifactFilter(); filter.add(new ScopeArtifactFilter("test")); filter.add(new InversionArtifactFilter(new DotnetSymbolsArtifactFilter())); dependencyResolution.require(project, LocalRepositoryUtil.create(localRepository), filter); } catch (ArtifactResolutionException e) { throw new MojoExecutionException( "NPANDAY-901-003: Could not satisfy required dependencies for scope " + "test", e); } }
From source file:npanday.plugin.resolver.CopyDependenciesMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { String skipReason = ""; if (!skip) {/*from w w w.j ava 2 s . c o m*/ ArtifactType knownType = ArtifactType.getArtifactTypeForPackagingName(project.getPackaging()); if (knownType.equals(ArtifactType.NULL)) { skip = true; skipReason = ", because the current project (type:" + project.getPackaging() + ") is not built with NPanday"; } } if (skip) { getLog().info("NPANDAY-158-001: Mojo for copying dependencies was intentionally skipped" + skipReason); return; } SettingsUtil.applyCustomSettings(getLog(), repositoryRegistry, settingsPath); AndArtifactFilter includeFilter = new AndArtifactFilter(); OrArtifactFilter typeIncludes = new OrArtifactFilter(); typeIncludes.add(new DotnetExecutableArtifactFilter()); typeIncludes.add(new DotnetLibraryArtifactFilter()); if (includePdbs) { typeIncludes.add(new DotnetSymbolsArtifactFilter()); } includeFilter.add(typeIncludes); if (!Strings.isNullOrEmpty(includeScope)) { includeFilter.add(new ScopeArtifactFilter(includeScope)); } Set<Artifact> artifacts; try { artifacts = dependencyResolution.require(project, LocalRepositoryUtil.create(localRepository), includeFilter); } catch (ArtifactResolutionException e) { throw new MojoExecutionException( "NPANDAY-158-003: dependency resolution for scope " + includeScope + " failed!", e); } /** * Should be resolved, but then not copied */ if (!Strings.isNullOrEmpty(excludeScope)) { includeFilter.add(new InversionArtifactFilter(new ScopeArtifactFilter(excludeScope))); } if (skipReactorArtifacts) { getLog().info("NPANDAY-158-008: " + reactorProjects); includeFilter.add(new InversionArtifactFilter(new ArtifactFilter() { public boolean include(Artifact artifact) { for (MavenProject project : reactorProjects) { // we don't care about the type and the classifier here if (project.getGroupId().equals(artifact.getGroupId()) && project.getArtifactId().equals(artifact.getArtifactId()) && project.getVersion().equals(artifact.getVersion())) { return true; } } return false; } })); } for (Artifact dependency : artifacts) { if (!includeFilter.include(dependency)) { getLog().debug("NPANDAY-158-006: dependency " + dependency + " was excluded"); continue; } try { File targetFile = new File(outputDirectory, PathUtil.getPlainArtifactFileName(dependency)); if (!targetFile.exists() || targetFile.lastModified() != dependency.getFile().lastModified() || targetFile.length() != dependency.getFile().length()) { getLog().info("NPANDAY-158-004: copy " + dependency.getFile() + " to " + targetFile); FileUtils.copyFile(dependency.getFile(), targetFile); } else { getLog().debug("NPANDAY-158-007: dependency " + dependency + " is yet up to date"); } } catch (IOException ioe) { throw new MojoExecutionException("NPANDAY-158-005: Error copying dependency " + dependency, ioe); } } }
From source file:npanday.plugin.resolver.ListDependenciesMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { String skipReason = ""; if (skip) {//from w ww . j a va 2 s . c o m getLog().info("NPANDAY-161-001: Mojo for listing dependencies was intentionally skipped" + skipReason); return; } SettingsUtil.applyCustomSettings(getLog(), repositoryRegistry, settingsPath); AndArtifactFilter includeFilter = new AndArtifactFilter(); if (!Strings.isNullOrEmpty(includeScope)) { includeFilter.add(new ScopeArtifactFilter(includeScope)); } Set<Artifact> artifacts; try { // TODO: Workarround. Somehow in the first run, PDBs wont be part of the result! dependencyResolution.require(project, LocalRepositoryUtil.create(localRepository), includeFilter); artifacts = dependencyResolution.require(project, LocalRepositoryUtil.create(localRepository), includeFilter); } catch (ArtifactResolutionException e) { throw new MojoExecutionException( "NPANDAY-161-003: dependency resolution for scope " + includeScope + " failed!", e); } /** * Should be resolved, but then not shown */ if (!Strings.isNullOrEmpty(excludeScope)) { includeFilter.add(new InversionArtifactFilter(new ScopeArtifactFilter(excludeScope))); } if (skipReactorArtifacts) { getLog().info("NPANDAY-161-008: " + reactorProjects); includeFilter.add(new InversionArtifactFilter(new ArtifactFilter() { public boolean include(Artifact artifact) { for (MavenProject project : reactorProjects) { // we don't care about the type and the classifier here if (project.getGroupId().equals(artifact.getGroupId()) && project.getArtifactId().equals(artifact.getArtifactId()) && project.getVersion().equals(artifact.getVersion())) { return true; } } return false; } })); } getLog().info("The following files have been resolved:"); for (Artifact dependency : artifacts) { if (!includeFilter.include(dependency)) { getLog().debug("NPANDAY-161-006: dependency " + dependency + " was excluded"); continue; } getLog().info(" " + dependency.getId() + ":" + dependency.getScope() + " -> " + dependency.getFile()); } }
From source file:npanday.plugin.resolver.ResolveMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { if (skip) {//from w w w .j a va2s. c om getLog().info("NPANDAY-149-001: Mojo for resolving dependencies was intentionally skipped"); return; } SettingsUtil.applyCustomSettings(getLog(), repositoryRegistry, settingsPath); getLog().warn( "NPANDAY-149-002: Mojo for resolving dependencies beforehand is executed! It should only be run, " + "if native maven plugins require special dependencies to be resolved!"); AndArtifactFilter filter = new AndArtifactFilter(); try { filter.add(new ScopeArtifactFilter(requiredScope)); if (!resolvePdbs) { filter.add(new InversionArtifactFilter(new DotnetSymbolsArtifactFilter())); } dependencyResolution.require(project, LocalRepositoryUtil.create(localRepository), filter); } catch (ArtifactResolutionException e) { throw new MojoExecutionException( "NPANDAY-149-003: early dependency resolution for scope " + requiredScope + " failed!", e); } }
From source file:org.codehaus.mojo.webstart.JnlpDownloadServletMojo.java
License:Apache License
/** * Resolve artifact of incoming jar resources (user configured ones), check their main class. * <p/>// w w w.j av a2 s . c om * If must include transitive dependencies, collect them and wrap them as new jar resources. * <p/> * For each collected jar resource, copy his artifact file to lib directory (if it has changed), * fill also his hrefValue if required (jar resource with outputJarVersion filled). * * @param configuredJarResources list of configured jar resources * @param commonJarResources list of resolved common jar resources (null when resolving common jar resources) * @return the set of resolved jar resources * @throws MojoExecutionException if something bas occurs while retrieving resources */ private Set<ResolvedJarResource> resolveJarResources(Collection<JarResource> configuredJarResources, Set<ResolvedJarResource> commonJarResources) throws MojoExecutionException { Set<ResolvedJarResource> collectedJarResources = new LinkedHashSet<ResolvedJarResource>(); if (commonJarResources != null) { collectedJarResources.addAll(commonJarResources); } ArtifactUtil artifactUtil = getArtifactUtil(); // artifacts resolved from repositories Set<Artifact> artifacts = new LinkedHashSet<Artifact>(); // sibling projects hit from a jar resources (need a special transitive resolution) Set<MavenProject> siblingProjects = new LinkedHashSet<MavenProject>(); // for each configured JarResource, create and resolve the corresponding artifact and // check it for the mainClass if specified for (JarResource jarResource : configuredJarResources) { Artifact artifact = artifactUtil.createArtifact(jarResource); // first try to resolv from reactor MavenProject siblingProject = artifactUtil.resolveFromReactor(artifact, getProject(), reactorProjects); if (siblingProject == null) { // try to resolve from repositories artifactUtil.resolveFromRepositories(artifact, getRemoteRepositories(), getLocalRepository()); artifacts.add(artifact); } else { artifact = siblingProject.getArtifact(); siblingProjects.add(siblingProject); artifacts.add(artifact); artifact.setResolved(true); } if (StringUtils.isNotBlank(jarResource.getMainClass())) { // check main class if (artifact == null) { throw new IllegalStateException( "Implementation Error: The given jarResource cannot be checked for " + "a main class until the underlying artifact has been resolved: [" + jarResource + "]"); } boolean containsMainClass = artifactUtil.artifactContainsClass(artifact, jarResource.getMainClass()); if (!containsMainClass) { throw new MojoExecutionException( "The jar specified by the following jarResource does not contain the declared main class:" + jarResource); } } ResolvedJarResource resolvedJarResource = new ResolvedJarResource(jarResource, artifact); getLog().debug("Add jarResource (configured): " + jarResource); collectedJarResources.add(resolvedJarResource); } if (!isExcludeTransitive()) { // prepare artifact filter AndArtifactFilter artifactFilter = new AndArtifactFilter(); // restricts to runtime and compile scope artifactFilter.add(new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME)); // restricts to not pom dependencies artifactFilter.add(new InversionArtifactFilter(new TypeArtifactFilter("pom"))); // get all transitive dependencies Set<Artifact> transitiveArtifacts = getArtifactUtil().resolveTransitively(artifacts, siblingProjects, getProject().getArtifact(), getLocalRepository(), getRemoteRepositories(), artifactFilter, getProject().getManagedVersionMap()); // for each transitive dependency, wrap it in a JarResource and add it to the collection of // existing jar resources (if not already in) for (Artifact resolvedArtifact : transitiveArtifacts) { ResolvedJarResource newJarResource = new ResolvedJarResource(resolvedArtifact); if (!collectedJarResources.contains(newJarResource)) { getLog().debug("Add jarResource (transitive): " + newJarResource); collectedJarResources.add(newJarResource); } } } // for each JarResource, copy its artifact to the lib directory if necessary for (ResolvedJarResource jarResource : collectedJarResources) { Artifact artifact = jarResource.getArtifact(); String filenameWithVersion = getDependencyFilenameStrategy().getDependencyFilename(artifact, false, isUseUniqueVersions()); boolean copied = copyJarAsUnprocessedToDirectoryIfNecessary(artifact.getFile(), getLibDirectory(), filenameWithVersion); if (copied) { String name = artifact.getFile().getName(); verboseLog("Adding " + name + " to modifiedJnlpArtifacts list."); getModifiedJnlpArtifacts().add(name.substring(0, name.lastIndexOf('.'))); } String filename = getDependencyFilenameStrategy().getDependencyFilename(artifact, jarResource.isOutputJarVersion() ? null : false, isUseUniqueVersions()); jarResource.setHrefValue(filename); } return collectedJarResources; }