List of usage examples for org.apache.maven.project MavenProject getArtifactId
public String getArtifactId()
From source file:org.smallmind.license.TargetLicenseMojo.java
License:Open Source License
@Override public void execute() throws MojoExecutionException, MojoFailureException { if ((new File(project.getBuild().getOutputDirectory())).exists()) { MavenProject rootProject = project; byte[] buffer = new byte[8192]; while ((root == null) ? !(rootProject.getParent() == null) : !(root.getGroupId().equals(rootProject.getGroupId()) && root.getArtifactId().equals(rootProject.getArtifactId()))) { rootProject = rootProject.getParent(); }// w w w .j ava 2 s.c o m for (String license : licenses) { File licenseFile; File copyFile; FileInputStream inputStream; FileOutputStream outputStream; int bytesRead; if (!(licenseFile = new File(license)).isAbsolute()) { licenseFile = new File(rootProject.getBasedir() + System.getProperty("file.separator") + licenseFile.getPath()); } if (!licenseFile.exists()) { getLog().warn( String.format("Unable to acquire the license file(%s), skipping license copying...", licenseFile.getAbsolutePath())); } else { if (verbose) { getLog().info(String.format("Copying license(%s)...", licenseFile.getName())); } copyFile = new File(project.getBuild().getOutputDirectory() + System.getProperty("file.separator") + licenseFile.getName()); try { outputStream = new FileOutputStream(copyFile); } catch (IOException ioException) { throw new MojoExecutionException( "Unable to create output license file (" + copyFile.getAbsolutePath() + ")", ioException); } try { inputStream = new FileInputStream(licenseFile); while ((bytesRead = inputStream.read(buffer)) >= 0) { outputStream.write(buffer, 0, bytesRead); } inputStream.close(); } catch (IOException ioException) { copyFile.delete(); throw new MojoExecutionException( "Problem in copying output license file (" + copyFile.getAbsolutePath() + ")", ioException); } try { outputStream.close(); } catch (IOException ioException) { throw new MojoExecutionException( "Problem in closing license file (" + licenseFile.getAbsolutePath() + ")", ioException); } } } } }
From source file:org.sonar.api.test.MavenTestUtils.java
License:Open Source License
public static Project loadProjectFromPom(Class clazz, String path) { MavenProject pom = loadPom(clazz, path); Project project = new Project(pom.getGroupId() + ":" + pom.getArtifactId()).setPom(pom); // configuration.setProperty("sonar.java.source", MavenUtils.getJavaSourceVersion(pom)); // configuration.setProperty("sonar.java.target", MavenUtils.getJavaVersion(pom)); // configuration.setProperty(CoreProperties.ENCODING_PROPERTY, MavenUtils.getSourceEncoding(pom)); project.setFileSystem(new MavenModuleFileSystem(pom)); return project; }
From source file:org.sonar.batch.maven.MavenProjectBuilder.java
License:Open Source License
private void setMavenProjectIfApplicable(ProjectDefinition definition) { if (mavenSession != null) { String moduleKey = definition.getKey(); for (MavenProject mavenModule : (List<MavenProject>) mavenSession.getSortedProjects()) { String mavenModuleKey = mavenModule.getGroupId() + ":" + mavenModule.getArtifactId(); if (mavenModuleKey.equals(moduleKey) && !definition.getContainerExtensions().contains(mavenModule)) { definition.addContainerExtension(mavenModule); }//from w ww . jav a 2 s . c o m } } }
From source file:org.sonar.batch.maven.MavenProjectConverter.java
License:Open Source License
private static String getSonarKey(MavenProject pom) { return new StringBuilder().append(pom.getGroupId()).append(":").append(pom.getArtifactId()).toString(); }
From source file:org.sonar.batch.MavenProjectBuilder.java
License:Open Source License
String loadProjectKey(MavenProject pom) { return new StringBuilder().append(pom.getGroupId()).append(":").append(pom.getArtifactId()).toString(); }
From source file:org.sonar.batch.MavenProjectConverter.java
License:Open Source License
/** * Visibility has been relaxed for tests. *//*from w w w . j a v a 2 s . c om*/ static ProjectDefinition convert(MavenProject pom) { String key = new StringBuilder().append(pom.getGroupId()).append(":").append(pom.getArtifactId()) .toString(); ProjectDefinition definition = ProjectDefinition.create(pom.getModel().getProperties()); definition.setKey(key).setVersion(pom.getVersion()).setName(pom.getName()) .setDescription(pom.getDescription()).addContainerExtension(pom); synchronizeFileSystem(pom, definition); return definition; }
From source file:org.sonar.batch.scan.maven.MavenProjectConverter.java
License:Open Source License
@VisibleForTesting static ProjectDefinition convert(MavenProject pom) { String key = new StringBuilder().append(pom.getGroupId()).append(":").append(pom.getArtifactId()) .toString();//ww w .j a v a 2s. c o m ProjectDefinition definition = ProjectDefinition.create(); // IMPORTANT NOTE : reference on properties from POM model must not be saved, // instead they should be copied explicitly - see SONAR-2896 definition.setProperties(pom.getModel().getProperties()).setKey(key).setVersion(pom.getVersion()) .setName(pom.getName()).setDescription(pom.getDescription()).addContainerExtension(pom); guessJavaVersion(pom, definition); guessEncoding(pom, definition); convertMavenLinksToProperties(definition, pom); synchronizeFileSystem(pom, definition); return definition; }
From source file:org.sonar.dev.UploadMojo.java
License:Open Source License
private void copyJar(MavenProject module) throws MojoExecutionException { File buildDir = new File(module.getBuild().getDirectory()); File jar = new File(buildDir, module.getBuild().getFinalName() + ".jar"); if (!jar.exists()) { throw new MojoExecutionException("Plugin artifact does not exist for module " + module.getArtifactId() + ": " + jar.getAbsolutePath()); }/*from ww w . j av a2 s. co m*/ getLog().info("Copying " + jar.getAbsolutePath()); File downloadsDir = new File(sonarHome, "extensions/downloads"); downloadsDir.mkdir(); try { FileUtils.copyFileToDirectory(jar, downloadsDir); } catch (IOException e) { throw new MojoExecutionException( String.format("Fail to copy %s to %s", jar.getAbsolutePath(), downloadsDir), e); } }
From source file:org.sonar.plugins.batch.maven.MavenProjectBuilder.java
License:Open Source License
private void setMavenProjectIfApplicable(ProjectDefinition definition) { if (mavenSession != null) { String moduleKey = definition.getKey(); for (MavenProject mavenModule : (List<MavenProject>) mavenSession.getProjects()) { // FIXME assumption that moduleKey was not modified by user and follow convention <groupId>:<artifactId> String mavenModuleKey = mavenModule.getGroupId() + ":" + mavenModule.getArtifactId(); if (mavenModuleKey.equals(moduleKey) && !definition.getContainerExtensions().contains(mavenModule)) { definition.addContainerExtension(mavenModule); }//from ww w .j a v a2 s . co m } } }
From source file:org.sonar.plugins.maven.MavenProjectConverter.java
License:Open Source License
public static String getSonarKey(MavenProject pom) { return new StringBuilder().append(pom.getGroupId()).append(":").append(pom.getArtifactId()).toString(); }