List of usage examples for org.apache.maven.project MavenProject getBasedir
public File getBasedir()
From source file:org.jboss.maven.plugins.qstools.common.ArtifactIdNameUtil.java
License:Apache License
/** * (non-Javadoc)/* ww w . j av a2 s . c om*/ * <p/> * Walks up the parent directories looking for the last containing a pom.xml with the same groupId as the specified project. */ private File getRootDirOfQuickstarts(MavenProject project) throws Exception { File dirToCheck = project.getBasedir(); File resultDir = project.getBasedir(); while (containsPomWithGroupId(dirToCheck, project.getGroupId())) { resultDir = dirToCheck; dirToCheck = dirToCheck.getParentFile(); } return resultDir; }
From source file:org.jboss.maven.plugins.qstools.common.PomNameUtil.java
License:Apache License
public String getExpectedPattern(MavenProject project, Rules rules) throws IOException { String pomNamePattern = rules.getPomNamePattern(); String pomNamePatternSubmodule = rules.getPomNamePatternForSubmodule(); String folderName = project.getBasedir().getName(); String parentFolder = project.getBasedir().getParentFile().getName(); String pattern;/* w w w . j a v a 2 s.co m*/ if (projectUtil.isSubProjec(project)) { // Get Target Product from parent Readme File parentReadme = new File(project.getBasedir().getParent(), "README.md"); String targetProject = getTargetProduct(parentReadme); pattern = pomNamePatternSubmodule.replace("<target-product>", targetProject) .replace("<project-folder>", parentFolder).replace("<submodule-folder>", folderName); } else { File readme = new File(project.getBasedir(), "README.md"); if (readme.exists()) { String targetProject = getTargetProduct(readme); pattern = pomNamePattern.replace("<target-product>", targetProject).replace("<project-folder>", folderName); } else { // Not able to get the targetProject. Using the existing name to avoid wrong violations pattern = project.getName(); } } return pattern; }
From source file:org.jboss.maven.plugins.qstools.fixers.JavaSourcesFormatFixer.java
License:Apache License
@SuppressWarnings("unchecked") @Override/* w w w.jav a 2s .c o m*/ public void fixProject(MavenProject project, Document doc) throws Exception { Rules rules = getConfigurationProvider().getQuickstartsRules(project.getGroupId()); // Read DefaultEclipseSettings Map<String, String> options = DefaultCodeFormatterConstants.getEclipseDefaultSettings(); // initialize the compiler settings to be able to format 1.6 code String compilerSource = rules.getExpectedCompilerSource(); options.put(JavaCore.COMPILER_COMPLIANCE, compilerSource); options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, compilerSource); options.put(JavaCore.COMPILER_SOURCE, compilerSource); // Configure CodeFormatter with Eclipse XML Formatter Profile InputStream xmlInputStream = resources .getFileInputStream(new URL(rules.getEclipseFormatterProfileLocation())); Document formatterSettingsDoc = PositionalXMLReader.readXML(xmlInputStream); NodeList settingsNodes = formatterSettingsDoc.getElementsByTagName("setting"); for (int i = 0; i < settingsNodes.getLength(); i++) { Node node = settingsNodes.item(i); String id = node.getAttributes().getNamedItem("id").getTextContent(); String value = node.getAttributes().getNamedItem("value").getTextContent(); options.put(id, value); } // Instantiate the default code formatter with the given options CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options); // Apply the formatter to every Java source under the project's folder List<File> javaSources = FileUtils.getFiles(project.getBasedir(), "**/*.java", ""); for (File javaSource : javaSources) { getLog().debug("Formating " + javaSource); String source = Files.toString(javaSource, Charset.forName("UTF-8")); TextEdit edit = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, // format a compilation unit source, // source to format 0, // starting position source.length(), // length 0, // initial indentation System.getProperty("line.separator") // line separator ); IDocument document = new org.eclipse.jface.text.Document(source); edit.apply(document); Files.write(document.get(), javaSource, Charset.forName("UTF-8")); } }
From source file:org.jboss.maven.plugins.qstools.fixers.ReadmeMetadataFixer.java
License:Apache License
@Override public void fixProject(MavenProject project, Document doc) throws Exception { File readme = new File(project.getBasedir(), "README.md"); regexPattern = readmeUtil.setupRegexPattern(project.getGroupId(), null); if (readme.exists()) { fixReadmeFile(project.getGroupId(), readme); }//from ww w . ja va 2s.co m }
From source file:org.jboss.maven.plugins.qstools.fixers.XMLTabFixer.java
License:Apache License
@Override public void fixProject(MavenProject project, Document doc) throws Exception { List<File> xmlFiles = FileUtils.getFiles(project.getBasedir(), "**/*.xml", ""); for (File xmlSource : xmlFiles) { getLog().debug("Fixing tab on " + xmlSource); String source = Files.toString(xmlSource, Charset.forName("UTF-8")); String replaced = source.replace("\t", " "); Files.write(replaced, xmlSource, Charset.forName("UTF-8")); }/*from w w w . j a v a 2 s.c o m*/ }
From source file:org.jboss.maven.shared.resource.ResourceDelegate.java
License:Open Source License
/** * Constructs a Delegate instance for handling Resource resolution. * * @param project The project currently being built. * @param baseTargetDirectory The base target directory to which we should copy resources. * @param defaultIncludes default patterns for resource copying inclusion. * @param defaultExcludes default patterns for resource copying exclusion. * @param log The log instance to use for logging. *///from ww w . j a v a 2s .c o m public ResourceDelegate(MavenProject project, File baseTargetDirectory, String[] defaultIncludes, String[] defaultExcludes, Log log) { this.basedir = project.getBasedir(); this.baseTargetDirectory = baseTargetDirectory; this.defaultIncludes = defaultIncludes; this.defaultExcludes = defaultExcludes; this.log = log; this.filterProperties = new CompositeMavenProjectProperties(project); }
From source file:org.jboss.tools.maven.jaxrs.configurators.JaxrsProjectConfigurator.java
License:Open Source License
private void installJaxRsFacet(IFacetedProject fproj, IProjectFacetVersion facetVersion, MavenProject mavenProject, IProgressMonitor monitor) throws CoreException { if (facetVersion != null) { IStatus status = facetVersion.getConstraint().check(fproj.getProjectFacets()); if (status.isOK()) { // refreshing the project hierarchy to make sure that Eclipse "sees" the .settings folder and file, // to be able to add the JAX-RS Facet. This only occurs if the projects are created via the project example UI. // see https://issues.jboss.org/browse/JBIDE-10037 ProjectUtil.refreshHierarchy(mavenProject.getBasedir(), IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 1)); IDataModel model = createJaxRsDataModel(fproj, facetVersion); String warSourceDirectory = getWarSourceDirectory(mavenProject, fproj.getProject()); model.setProperty(IJAXRSFacetInstallDataModelProperties.WEBCONTENT_DIR, warSourceDirectory); model.setProperty(IJAXRSFacetInstallDataModelProperties.UPDATEDD, false); fproj.installProjectFacet(facetVersion, model, monitor); } else {/* w w w .j a v a2s.com*/ addErrorMarker(fproj.getProject(), facetVersion + " can not be installed : " + status.getMessage()); for (IStatus st : status.getChildren()) { addErrorMarker(fproj.getProject(), st.getMessage()); } } } }
From source file:org.jenkinsci.plugins.pipeline.maven.eventspy.handler.AbstractMavenEventHandler.java
License:Open Source License
public Xpp3Dom newElement(@Nonnull String name, @Nullable final MavenProject project) { Xpp3Dom projectElt = new Xpp3Dom(name); if (project == null) { return projectElt; }// www. ja va 2 s. c om projectElt.setAttribute("name", project.getName()); projectElt.setAttribute("groupId", project.getGroupId()); projectElt.setAttribute("artifactId", project.getArtifactId()); projectElt.setAttribute("version", project.getVersion()); projectElt.setAttribute("packaging", project.getPackaging()); if (project.getBasedir() != null) { try { projectElt.setAttribute("baseDir", project.getBasedir().getCanonicalPath()); } catch (IOException e) { throw new RuntimeIOException(e); } } if (project.getFile() != null) { File projectFile = project.getFile(); String absolutePath; try { absolutePath = projectFile.getCanonicalPath(); } catch (IOException e) { throw new RuntimeIOException(e); } if (absolutePath.endsWith(File.separator + "pom.xml") || absolutePath.endsWith(File.separator + ".flattened-pom.xml")) { // JENKINS-43616: flatten-maven-plugin replaces the original pom as artifact with a .flattened-pom.xml // no tweak } else if (absolutePath.endsWith(File.separator + "dependency-reduced-pom.xml")) { // JENKINS-42302: maven-shade-plugin creates a temporary project file dependency-reduced-pom.xml // TODO see if there is a better way to implement this "workaround" absolutePath = absolutePath.replace(File.separator + "dependency-reduced-pom.xml", File.separator + "pom.xml"); } else if (absolutePath.endsWith(File.separator + ".git-versioned-pom.xml")) { // JENKINS-56666 maven-git-versioning-extension causes warnings due to temporary pom.xml file name '.git-versioned-pom.xml' // https://github.com/qoomon/maven-git-versioning-extension/blob/v4.1.0/src/main/java/me/qoomon/maven/gitversioning/VersioningMojo.java#L39 // TODO see if there is a better way to implement this "workaround" absolutePath = absolutePath.replace(File.separator + ".git-versioned-pom.xml", File.separator + "pom.xml"); } else { String flattenedPomFilename = getMavenFlattenPluginFlattenedPomFilename(project); if (flattenedPomFilename == null) { logger.warn("[jenkins-event-spy] Unexpected Maven project file name '" + projectFile.getName() + "', problems may occur"); } else { if (absolutePath.endsWith(File.separator + flattenedPomFilename)) { absolutePath = absolutePath.replace(File.separator + flattenedPomFilename, File.separator + "pom.xml"); } else { logger.warn("[jenkins-event-spy] Unexpected Maven project file name '" + projectFile.getName() + "', problems may occur"); } } } projectElt.setAttribute("file", absolutePath); } Build build = project.getBuild(); if (build != null) { Xpp3Dom buildElt = new Xpp3Dom("build"); projectElt.addChild(buildElt); if (build.getOutputDirectory() != null) { buildElt.setAttribute("directory", build.getDirectory()); } if (build.getSourceDirectory() != null) { buildElt.setAttribute("sourceDirectory", build.getSourceDirectory()); } } return projectElt; }
From source file:org.jfrog.jade.plugins.common.ant.Maven2AntManagerDefaultImpl.java
License:Apache License
/** * Create a new Ant project from the mvnInjectable. * This method can be overrriden if needed by sub class for fine tuning of maven 2 ant. * * @param injectable/*w ww. j a v a 2s . c o m*/ * @return a new Ant project */ protected Project newAntProject(MvnInjectable injectable) { Project antProject = new Project(); antProject.addBuildListener(new AntBuildListener(injectable.getLog())); MavenProject mvnProject = injectable.getProject(); if (mvnProject == null) { throw new IllegalArgumentException("Maven project cannot be null."); } antProject.setBaseDir(mvnProject.getBasedir()); antProject.init(); return antProject; }
From source file:org.jfrog.jade.plugins.idea.IdeaCleanMojo.java
License:Apache License
private File getIdeaFile(String extension) { MavenProject project = getProject(); return new File(project.getBasedir(), getNameProvider().getProjectName(project) + extension); }