List of usage examples for org.apache.maven.project MavenProject getBasedir
public File getBasedir()
From source file:com.parasoft.xtest.reports.jenkins.ParasoftReporter.java
License:Apache License
@Override public ParserResult perform(final MavenBuildProxy build, final MavenProject pom, final MojoInfo mojo, final PluginLogger logger) throws InterruptedException, IOException { logger.log(Messages.COLLECTING_REPORT_FILES); File file = pom.getBasedir(); logger.log(file.getAbsolutePath());/*from w ww. j av a 2s .c o m*/ PublisherHelper helper = new PublisherHelper(getTargetPath(pom), getSettingsPath(), getReportFilesPattern(), getReportCheckField()); Logger.getLogger().info("Report location: " + helper.getReportLocation().getRemote()); //$NON-NLS-1$ ParasoftParser parser = new ParasoftParser(getDefaultEncoding(), helper.getSettings()); FilesParser parasoftCollector = new FilesParser(PLUGIN_NAME, helper.getReportPattern(), parser, false, true, false); ParserResult result = helper.getReportLocation().act(parasoftCollector); helper.storeLocalSettings(build.getRootDir()); return result; }
From source file:com.puppetlabs.geppetto.forge.maven.plugin.AbstractForgeMojo.java
License:Open Source License
/** * Returns the basedir as an absolute path string without any '..' constructs. * /*from ww w . j a va 2 s. co m*/ * @return The absolute path of basedir */ public File getBasedir() { if (baseDir == null) { MavenProject project = session.getCurrentProject(); URI basedirURI; File pbd = project.getBasedir(); if (pbd != null) basedirURI = pbd.toURI(); else basedirURI = URI.create(session.getExecutionRootDirectory()); try { baseDir = new File(basedirURI.normalize()); } catch (IllegalArgumentException e) { // URI is not absolute. Try and make it relative to the current directory URI here = new File(".").getAbsoluteFile().toURI(); baseDir = new File(here.resolve(basedirURI).normalize()); } } return baseDir; }
From source file:com.rodiontsev.maven.plugins.buildinfo.providers.AbstractVcsInfoProvider.java
License:Apache License
protected boolean isDirectoryExists(MavenProject project, String child) { boolean result = false; try {/* www . j a v a2s. com*/ File dir = lookup(project.getBasedir(), child); result = (dir.exists() && dir.isDirectory()); //redundant check } catch (FileNotFoundException e) { //do nothing } return result; }
From source file:com.rodiontsev.maven.plugins.buildinfo.providers.GitInfoProvider.java
License:Apache License
@Override protected Map<String, String> getScmInfo(MavenProject project, BuildInfoMojo mojo) { File basedir = project.getBasedir(); ScmLogger logger = new DefaultLog(); ScmFileSet fileSet = new ScmFileSet(basedir); GitCommand infoCommand = new GitExeScmProvider().getInfoCommand(); infoCommand.setLogger(logger);// w ww. j a v a 2 s. c o m InfoScmResult infoResult = null; try { ScmProviderRepository repository = new GitScmProviderRepository(basedir.getAbsolutePath()); CommandParameters parameters = new CommandParameters(); infoResult = (InfoScmResult) infoCommand.execute(repository, fileSet, parameters); } catch (ScmException e) { if (logger.isErrorEnabled()) { logger.error(e.getMessage()); } } Map<String, String> info = new LinkedHashMap<String, String>(); if (infoResult != null) { if (infoResult.isSuccess()) { List<InfoItem> items = infoResult.getInfoItems(); if ((items != null) && (items.size() == 1)) { info.put("git.revision", items.get(0).getRevision()); } else { info.put("git.error", "The command returned incorrect number of arguments"); } } else { info.put("git.error", infoResult.getProviderMessage()); } } return info; }
From source file:com.rodiontsev.maven.plugins.buildinfo.providers.MercurialInfoProvider.java
License:Apache License
@Override protected Map<String, String> getScmInfo(MavenProject project, BuildInfoMojo mojo) { ScmLogger logger = new DefaultLog(); HgLogConsumer consumer = new HgLogConsumer(logger); ScmResult result = null;/* www . j a va 2 s . c o m*/ try { result = HgUtils.execute(consumer, logger, project.getBasedir(), new String[] { HgCommandConstants.REVNO_CMD, "-n", "-i", "-b" }); } catch (ScmException e) { if (logger.isErrorEnabled()) { logger.error(e.getMessage()); } } Map<String, String> info = new LinkedHashMap<String, String>(); if (result != null) { if (result.isSuccess()) { String output = result.getCommandOutput(); if (output != null) { Matcher matcher = HG_OUTPUT_PATTERN.matcher(output); if (matcher.find() && matcher.groupCount() == 3) { StringBuilder changeset = new StringBuilder(); changeset.append("r").append(matcher.group(2)).append(":").append(matcher.group(1)); info.put("hg.changeset", changeset.toString()); info.put("hg.branch", matcher.group(3)); } else { info.put("hg.error", "The command returned incorrect number of arguments"); } } } else { info.put("hg.error", result.getProviderMessage()); } } return info; }
From source file:com.rodiontsev.maven.plugins.buildinfo.providers.SubversionInfoProvider.java
License:Apache License
@Override protected Map<String, String> getScmInfo(MavenProject project, BuildInfoMojo mojo) { File basedir = project.getBasedir(); ScmLogger logger = new DefaultLog(); ScmFileSet fileSet = new ScmFileSet(basedir); SvnCommand infoCommand = new SvnExeScmProvider().getInfoCommand(); infoCommand.setLogger(logger);// w w w. j av a 2 s. co m InfoScmResult infoResult = null; try { ScmProviderRepository repository = new SvnScmProviderRepository(basedir.getAbsolutePath()); CommandParameters parameters = new CommandParameters(); infoResult = (InfoScmResult) infoCommand.execute(repository, fileSet, parameters); } catch (ScmException e) { if (logger.isErrorEnabled()) { logger.error(e.getMessage()); } } Map<String, String> info = new LinkedHashMap<String, String>(); if (infoResult != null) { if (infoResult.isSuccess()) { List<InfoItem> items = infoResult.getInfoItems(); if ((items != null) && (items.size() == 1)) { InfoItem item = items.get(0); info.put("svn.url", item.getURL()); info.put("svn.revision", item.getRevision()); info.put("svn.last.changed.author", item.getLastChangedAuthor()); info.put("svn.last.changed.revision", item.getLastChangedRevision()); info.put("svn.last.changed.date", item.getLastChangedDate()); } } else { info.put("svn.info.error", infoResult.getProviderMessage()); } } return info; }
From source file:com.sap.prd.mobile.ios.mios.FolderLayout.java
License:Apache License
/** * Checks if the source folder location has been explicitly set by the "xcode.sourceDirectory". If * not the default "src/xcode" is returned. *///from ww w.j ava 2 s . c o m static File getSourceFolder(MavenProject project) { final Properties projectProperties = project.getProperties(); if (projectProperties.containsKey(XCodeDefaultConfigurationMojo.XCODE_SOURCE_DIRECTORY)) { return new File(project.getBasedir(), projectProperties.getProperty(XCodeDefaultConfigurationMojo.XCODE_SOURCE_DIRECTORY)); } return new File(project.getBasedir(), XCodeDefaultConfigurationMojo.DEFAULT_XCODE_SOURCE_DIRECTORY); }
From source file:com.serli.maven.plugin.quality.mojo.LicenseMojo.java
License:Open Source License
/** * @param project//from w ww . j a v a 2s . c om * not null * @param url * not null * @return a valid URL object from the url string * @throws IOException * if any */ protected static URL getLicenseURL(MavenProject project, String url) throws IOException { URL licenseUrl = null; UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_ALL_SCHEMES); // UrlValidator does not accept file URLs because the file // URLs do not contain a valid authority (no hostname). // As a workaround accept license URLs that start with the // file scheme. if (urlValidator.isValid(url) || StringUtils.defaultString(url).startsWith("file://")) { try { licenseUrl = new URL(url); } catch (MalformedURLException e) { throw new MalformedURLException( "The license url '" + url + "' seems to be invalid: " + e.getMessage()); } } else { File licenseFile = new File(project.getBasedir(), url); if (!licenseFile.exists()) { // Workaround to allow absolute path names while // staying compatible with the way it was... licenseFile = new File(url); } if (!licenseFile.exists()) { throw new IOException("Maven can't find the file '" + licenseFile + "' on the system."); } try { licenseUrl = licenseFile.toURI().toURL(); } catch (MalformedURLException e) { throw new MalformedURLException( "The license url '" + url + "' seems to be invalid: " + e.getMessage()); } } return licenseUrl; }
From source file:com.simpligility.maven.plugins.android.common.UnpackedLibHelper.java
License:Open Source License
public UnpackedLibHelper(ArtifactResolverHelper artifactResolverHelper, MavenProject project, Logger log, File unpackedLibsFolder) { this.artifactResolverHelper = artifactResolverHelper; if (unpackedLibsFolder != null) { // if absolute then use it. // if relative then make it relative to the basedir of the project. this.unpackedLibsDirectory = unpackedLibsFolder.isAbsolute() ? unpackedLibsFolder : new File(project.getBasedir(), unpackedLibsFolder.getPath()); } else {// w w w. j av a2s . c o m // If not specified then default to target/unpacked-libs final File targetFolder = new File(project.getBuild().getDirectory()); this.unpackedLibsDirectory = new File(targetFolder, "unpacked-libs"); } this.log = log; }
From source file:com.slim.service.BuildService.java
License:Apache License
public void buildear(MavenProject project, String outputDirectory, String archiveURI, String traHome, Log logger) throws MojoExecutionException { logger.info(" - BASE_DIR : " + project.getBasedir().toString()); logger.info(" - TRA_HOME : " + traHome); logger.info(" - OUTPUT_DIRECTORY : " + outputDirectory); try {/*from www .ja va 2s. co m*/ CommandUtils.createDirectoryIfNeeded(project.getBasedir().toString() + "\\" + outputDirectory, logger); if (archiveURI == null || archiveURI.length() == 0) { archiveURI = "/" + project.getArtifact().getArtifactId(); } Map<String, String> options = new HashMap<String, String>(); options.put("-v", ""); options.put("-xs", ""); options.put(CommandUtils.EAR_OPTION, CommandUtils.GUILLEMETS + archiveURI + CommandUtils.GUILLEMETS); options.put(CommandUtils.PROJECT_OPTION, CommandUtils.GUILLEMETS + project.getBasedir().toString() + "\\" + project.getArtifact().getArtifactId() + CommandUtils.GUILLEMETS); options.put(CommandUtils.O_OPTION, CommandUtils.GUILLEMETS + project.getBasedir().toString() + "\\" + outputDirectory + "\\" + project.getArtifact().getArtifactId() + ".ear" + CommandUtils.GUILLEMETS); BufferedReader buildOutput = CommandUtils.executeCommand(logger, traHome, CommandUtils.getBuildEarBin(), options); boolean isError = false; StringBuffer result = new StringBuffer(); String line = null; while ((line = buildOutput.readLine()) != null) { if (line.contains("Error")) { isError = true; } result.append(line + "\n"); } if (isError) { logger.error(result.toString()); throw new Exception("Error in building ear ..."); } else { logger.info(result.toString()); } } catch (IOException e) { e.printStackTrace(); throw new MojoExecutionException("Error", e); } catch (Throwable e) { e.printStackTrace(); throw new MojoExecutionException("Error", e); } }