Java Code Examples for org.apache.maven.project.MavenProject#getBuild()

The following examples show how to use org.apache.maven.project.MavenProject#getBuild() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CosChecker.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static File getCoSFile(MavenProject mp, boolean test) {
    if (mp == null) {
        return null;
    }
    Build build = mp.getBuild();
    if (build == null) {
        return null;
    }
    String path = test ? build.getTestOutputDirectory() : build.getOutputDirectory();
    if (path == null) {
        return null;
    }
    File fl = new File(path);
    fl = FileUtil.normalizeFile(fl);
    return  new File(fl, NB_COS);
}
 
Example 2
Source File: CheckPluginDependencyVersions.java    From unleash-maven-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private Multimap<ArtifactCoordinates, ArtifactCoordinates> getSnapshotsFromManagement(MavenProject project,
    PomPropertyResolver propertyResolver) {
  this.log.debug("\t\tChecking managed plugins");
  Multimap<ArtifactCoordinates, ArtifactCoordinates> result = HashMultimap.create();
  Build build = project.getBuild();
  if (build != null) {
    PluginManagement pluginManagement = build.getPluginManagement();
    if (pluginManagement != null) {
      for (Plugin plugin : pluginManagement.getPlugins()) {
        Collection<Dependency> snapshots = Collections2.filter(plugin.getDependencies(),
            new IsSnapshotDependency(propertyResolver));
        if (!snapshots.isEmpty()) {
          result.putAll(PluginToCoordinates.INSTANCE.apply(plugin),
              Collections2.transform(snapshots, DependencyToCoordinates.INSTANCE));
        }
      }
    }
  }
  return result;
}
 
Example 3
Source File: CheckPluginDependencyVersions.java    From unleash-maven-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private Multimap<ArtifactCoordinates, ArtifactCoordinates> getSnapshots(MavenProject project,
    PomPropertyResolver propertyResolver) {
  this.log.debug("\t\tChecking direct plugin references");
  Multimap<ArtifactCoordinates, ArtifactCoordinates> result = HashMultimap.create();
  Build build = project.getBuild();
  if (build != null) {
    for (Plugin plugin : build.getPlugins()) {
      Collection<Dependency> snapshots = Collections2.filter(plugin.getDependencies(),
          new IsSnapshotDependency(propertyResolver));
      if (!snapshots.isEmpty()) {
        result.putAll(PluginToCoordinates.INSTANCE.apply(plugin),
            Collections2.transform(snapshots, DependencyToCoordinates.INSTANCE));
      }
    }
  }
  return result;
}
 
Example 4
Source File: DockerAssemblyManager.java    From docker-maven-plugin with Apache License 2.0 6 votes vote down vote up
private File ensureThatArtifactFileIsSet(MavenProject project) {
    Artifact artifact = project.getArtifact();
    if (artifact == null) {
        return null;
    }
    File oldFile = artifact.getFile();
    if (oldFile != null) {
        return oldFile;
    }
    Build build = project.getBuild();
    if (build == null) {
        return null;
    }
    String finalName = build.getFinalName();
    String target = build.getDirectory();
    if (finalName == null || target == null) {
        return null;
    }
    File artifactFile = new File(target, finalName + "." + project.getPackaging());
    if (artifactFile.exists() && artifactFile.isFile()) {
        setArtifactFile(project, artifactFile);
    }
    return null;
}
 
Example 5
Source File: CheckPluginVersions.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private Set<ArtifactCoordinates> getSnapshotsFromManagement(MavenProject project,
    PomPropertyResolver propertyResolver) {
  this.log.debug("\t\tChecking managed plugins");
  Build build = project.getBuild();
  if (build != null) {
    PluginManagement pluginManagement = build.getPluginManagement();
    if (pluginManagement != null) {
      Collection<Plugin> snapshots = Collections2.filter(pluginManagement.getPlugins(),
          new IsSnapshotPlugin(propertyResolver));
      return Sets.newHashSet(Collections2.transform(snapshots, PluginToCoordinates.INSTANCE));
    }
  }
  return Collections.emptySet();
}
 
Example 6
Source File: CheckPluginVersions.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private Set<ArtifactCoordinates> getSnapshots(MavenProject project, PomPropertyResolver propertyResolver) {
  this.log.debug("\t\tChecking direct plugin references");
  Build build = project.getBuild();
  if (build != null) {
    Collection<Plugin> snapshots = Collections2.filter(build.getPlugins(), new IsSnapshotPlugin(propertyResolver));
    return Sets.newHashSet(Collections2.transform(snapshots, PluginToCoordinates.INSTANCE));
  }
  return Collections.emptySet();
}
 
Example 7
Source File: MavenSharabilityQueryImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public @Override SharabilityQuery.Sharability getSharability(URI uri) {
    //#119541 for the project's root, return MIXED right away.
    File file = FileUtil.normalizeFile(Utilities.toFile(uri));
    FileObject fo = FileUtil.toFileObject(file);
    if (fo != null && fo.equals(project.getProjectDirectory())) {
        return SharabilityQuery.Sharability.MIXED;
    }
    File basedir = FileUtil.toFile(project.getProjectDirectory());
    // is this condition necessary?
    if (!file.getAbsolutePath().startsWith(basedir.getAbsolutePath())) {
        return SharabilityQuery.Sharability.UNKNOWN;
    }
    if (basedir.equals(file.getParentFile())) {
        // Interesting cases are of direct children.
        if (file.getName().equals("pom.xml")) { // NOI18N
            return SharabilityQuery.Sharability.SHARABLE;
        }
        if ("nbproject".equals(file.getName())) { //NOI18N
            // screw the netbeans profiler directory creation.
            // #98662
            return SharabilityQuery.Sharability.NOT_SHARABLE;
        }
        if (file.getName().startsWith("nbactions")) { //NOI18N
            //non shared custom configurations shall not be added to version control.
            M2ConfigProvider configs = project.getLookup().lookup(M2ConfigProvider.class);
            if (configs != null) {
                Collection<M2Configuration> col = configs.getNonSharedConfigurations();
                for (M2Configuration conf : col) {
                    if (file.getName().equals(M2Configuration.getFileNameExt(conf.getId()))) {
                        return SharabilityQuery.Sharability.NOT_SHARABLE;
                    }
                }
            }
        }
        if (file.getName().equals("src")) { // NOI18N
            // hardcoding this name since Maven will only report particular subtrees
            return SharabilityQuery.Sharability.SHARABLE; // #174010
        }
    }

    //this part is slow if invoked on built project that is not opened (needs to load the embedder)
    //can it be replaced with code not touching the embedder?
    MavenProject proj = project.getLookup().lookup(NbMavenProject.class).getMavenProject();
    Build build = proj.getBuild();
    if (build != null && build.getDirectory() != null) {
        File target = new File(build.getDirectory());
        if (target.equals(file) || file.getAbsolutePath().startsWith(target.getAbsolutePath())) {
            return SharabilityQuery.Sharability.NOT_SHARABLE;
        }
    }

    // Some other subdir with potentially unknown contents.
    if (file.isDirectory()) {
        return SharabilityQuery.Sharability.MIXED;
    } else {
        return SharabilityQuery.Sharability.UNKNOWN;
    }
}
 
Example 8
Source File: GenProgMojo.java    From repairnator with MIT License 4 votes vote down vote up
private AstorContext createAstorContext() {
 AstorContext context = new AstorContext();
 context.out = outputDirectory.getAbsolutePath();
 context.Package = packageToInstrument;
 context.scope = scope;
 context.flThreshold = localisationThreshold;
    context.seed = seed;
    context.maxGen = maxgen;
    context.maxTime = maxtime;
    context.location = project.getBasedir().getAbsolutePath();
    context.stopFirst = stopfirst;
    context.mode = mode;
    context.javaComplianceLevel = getComplianceLevel();
    context.skipfaultlocalization = skipfaultlocalization;

    for (int i = 0; i < getFailingTests().size(); i++) {
        String test = getFailingTests().get(i);
        context.failing.add(test);
    }

    final List<URL> dependencies = getClasspath();

    for (MavenProject mavenProject : reactorProjects) {
        Build build = mavenProject.getBuild();
        context.srcJavaFolder.add(getRelativePath(build.getSourceDirectory()));
        context.srcTestFolder.add(getRelativePath(build.getTestSourceDirectory()));
        context.binJavaFolder.add(getRelativePath(build.getOutputDirectory()));
        context.binTestFolder.add(getRelativePath(build.getTestOutputDirectory()));
    }

    for (int i = 0; i < dependencies.size(); i++) {
        URL url = dependencies.get(i);
        String path = url.getPath();
        if (context.binTestFolder.contains(getRelativePath(path))
                || context.binJavaFolder.contains(getRelativePath(path))) {
            continue;
        }
        context.dependencies.add(path);
    }
    if (context.dependencies.isEmpty()) {
        context.dependencies.add(dependencies.get(0).getPath());
    }


    return context;
}