diff options
Diffstat (limited to 'sonar-plugin-api')
28 files changed, 5 insertions, 1552 deletions
diff --git a/sonar-plugin-api/pom.xml b/sonar-plugin-api/pom.xml index 2c911baec34..2930c541710 100644 --- a/sonar-plugin-api/pom.xml +++ b/sonar-plugin-api/pom.xml @@ -87,20 +87,6 @@ </dependency> - <!-- TODO remove dependencies on Maven - but for now they should be defined with scope provided - --> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-plugin-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-core</artifactId> - <scope>provided</scope> - </dependency> - <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/ProjectClasspath.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/ProjectClasspath.java deleted file mode 100644 index 8349748a14c..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/ProjectClasspath.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.api.batch; - -import org.apache.maven.artifact.DependencyResolutionRequiredException; -import org.apache.maven.project.MavenProject; -import org.sonar.api.utils.SonarException; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.List; - -/** - * @since 2.2 - * @deprecated since 4.5 this is some Java specific stuff that should by handled by SQ Java plugin - */ -@Deprecated -@BatchSide -public class ProjectClasspath { - - protected MavenProject pom; - private List<File> elements; - private URLClassLoader classloader; - - public ProjectClasspath(MavenProject pom) { - this.pom = pom; - } - - public URLClassLoader getClassloader() { - if (classloader == null) { - classloader = createClassLoader(); - } - return classloader; - } - - /** - * bytecode directory + JARs (dependencies) - */ - public List<File> getElements() { - if (elements == null) { - elements = createElements(); - } - return elements; - } - - protected URLClassLoader createClassLoader() { - try { - List<URL> urls = new ArrayList<>(); - for (File file : getElements()) { - urls.add(file.toURI().toURL()); - } - return new URLClassLoader(urls.toArray(new URL[urls.size()]), null); - - } catch (MalformedURLException e) { - throw new SonarException("Fail to create the project classloader. Classpath element is unvalid.", e); - } - } - - protected List<File> createElements() { - try { - List<File> files = new ArrayList<>(); - if (pom.getCompileClasspathElements() != null) { - for (String classPathString : pom.getCompileClasspathElements()) { - files.add(new File(classPathString)); - } - } - - if (pom.getBuild().getOutputDirectory() != null) { - File outputDirectoryFile = new File(pom.getBuild().getOutputDirectory()); - if (outputDirectoryFile.exists()) { - files.add(outputDirectoryFile); - } - } - return files; - } catch (DependencyResolutionRequiredException e) { - throw new SonarException("Fail to create the project classloader", e); - } - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenPlugin.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenPlugin.java deleted file mode 100644 index a73c125ae8c..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenPlugin.java +++ /dev/null @@ -1,432 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.api.batch.maven; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.ReportPlugin; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.xml.Xpp3Dom; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -/** - * A class to handle maven plugins - * - * @since 1.10 - * @deprecated since 4.5 we don't want any dependency on Maven anymore - */ -@Deprecated -public class MavenPlugin { - - private static final String CONFIGURATION_ELEMENT = "configuration"; - private Plugin plugin; - private Xpp3Dom configuration; - - /** - * Creates a MavenPlugin based on a Plugin - * - * @param plugin the plugin - */ - public MavenPlugin(Plugin plugin) { - this.plugin = plugin; - this.configuration = (Xpp3Dom) plugin.getConfiguration(); - if (this.configuration == null) { - configuration = new Xpp3Dom(CONFIGURATION_ELEMENT); - plugin.setConfiguration(this.configuration); - } - } - - /** - * Creates a Maven plugin based on artifact + group + version - * - * @param groupId the group id - * @param artifactId the artifact id - * @param version the version - */ - public MavenPlugin(String groupId, String artifactId, String version) { - this.plugin = new Plugin(); - plugin.setGroupId(groupId); - plugin.setArtifactId(artifactId); - plugin.setVersion(version); - configuration = new Xpp3Dom(CONFIGURATION_ELEMENT); - plugin.setConfiguration(this.configuration); - } - - /** - * @since 3.5 - see SONAR-4070 - * @return the XML node <configuration> of pom - */ - public Xpp3Dom getConfigurationXmlNode() { - return configuration; - } - - /** - * Sets the maven plugin version - * - * @param version the version - * @return this - */ - public MavenPlugin setVersion(String version) { - this.plugin.setVersion(version); - return this; - } - - /** - * @return the underlying plugin - */ - public Plugin getPlugin() { - return plugin; - } - - /** - * Gets a parameter of the plugin based on its key - * - * @param key the param key - * @return the parameter if exist, null otherwise - */ - public String getParameter(String key) { - Xpp3Dom node = findNodeWith(key); - return node == null ? null : node.getValue(); - } - - /** - * Gets a list of parameters of the plugin from a param key - * - * @param key param key with option-index snippet: e.g. item[0], item[1]. If no index snippet is passed, then - * 0 is default (index <=> index[0]) - * @return an array of parameters if any, an empty array otherwise - */ - public String[] getParameters(String key) { - String[] keyParts = StringUtils.split(key, "/"); - Xpp3Dom node = configuration; - for (int i = 0; i < keyParts.length - 1; i++) { - node = getOrCreateChild(node, keyParts[i]); - } - Xpp3Dom[] children = node.getChildren(keyParts[keyParts.length - 1]); - String[] result = new String[children.length]; - for (int i = 0; i < children.length; i++) { - result[i] = children[i].getValue(); - } - return result; - } - - /** - * Sets a parameter for the maven plugin. This will overrides an existing parameter. - * - * @param key the param key - * @param value the param value - * @return this - */ - public MavenPlugin setParameter(String key, String value) { - checkKeyArgument(key); - String[] keyParts = StringUtils.split(key, "/"); - Xpp3Dom node = configuration; - for (String keyPart : keyParts) { - node = getOrCreateChild(node, keyPart); - } - node.setValue(value); - return this; - } - - /** - * Sets a parameter to the maven plugin. Overrides existing parameter only id specified. - * - * @param key the param key - * @param value the param value - * @param override whether to override existing parameter - */ - public void setParameter(String key, String value, boolean override) { - if (getParameter(key) == null || override) { - setParameter(key, value); - } - } - - /** - * Removes all parameters from the maven plugin - */ - public void removeParameters() { - configuration = new Xpp3Dom(CONFIGURATION_ELEMENT); - plugin.setConfiguration(this.configuration); - } - - /** - * Adds a parameter to the maven plugin - * - * @param key the param key with option-index snippet: e.g. item[0], item[1]. If no index snippet is passed, then - * 0 is default (index <=> index[0]) - * @param value the param value - * @return this - */ - public MavenPlugin addParameter(String key, String value) { - String[] keyParts = StringUtils.split(key, "/"); - Xpp3Dom node = configuration; - for (int i = 0; i < keyParts.length - 1; i++) { - node = getOrCreateChild(node, keyParts[i]); - } - Xpp3Dom leaf = new Xpp3Dom(keyParts[keyParts.length - 1]); - leaf.setValue(value); - node.addChild(leaf); - return this; - } - - private static Xpp3Dom getOrCreateChild(Xpp3Dom node, String key) { - int childIndex = getIndex(key); - - if (node.getChildren(removeIndexSnippet(key)).length <= childIndex) { - Xpp3Dom child = new Xpp3Dom(removeIndexSnippet(key)); - node.addChild(child); - return child; - } - return node.getChildren(removeIndexSnippet(key))[childIndex]; - - } - - private static int getIndex(String key) { - // parsing index-syntax (e.g. item[1]) - if (key.matches(".*?\\[\\d+\\]")) { - return Integer.parseInt(StringUtils.substringBetween(key, "[", "]")); - } - // for down-compatibility of api we fallback to default 0 - return 0; - } - - private static String removeIndexSnippet(String key) { - return StringUtils.substringBefore(key, "["); - } - - /** - * Remove a parameter from the maven plugin based on its key - * - * @param key param key with option-index snippet: e.g. item[0], item[1]. If no index snippet is passed, then - * 0 is default (index <=> index[0]) - */ - public void removeParameter(String key) { - Xpp3Dom node = findNodeWith(key); - if (node != null) { - remove(node); - } - } - - private Xpp3Dom findNodeWith(String key) { - checkKeyArgument(key); - String[] keyParts = key.split("/"); - Xpp3Dom node = configuration; - for (String keyPart : keyParts) { - - if (node.getChildren(removeIndexSnippet(keyPart)).length <= getIndex(keyPart)) { - return null; - } - - node = node.getChildren(removeIndexSnippet(keyPart))[getIndex(keyPart)]; - if (node == null) { - return null; - } - } - return node; - } - - private static void remove(Xpp3Dom node) { - Xpp3Dom parent = node.getParent(); - for (int i = 0; i < parent.getChildCount(); i++) { - Xpp3Dom child = parent.getChild(i); - if (child.equals(node)) { - parent.removeChild(i); - break; - } - } - } - - /** - * @return whether the maven plugin has got configuration - */ - public boolean hasConfiguration() { - return configuration.getChildCount() > 0; - } - - private static void checkKeyArgument(String key) { - if (key == null) { - throw new IllegalArgumentException("Parameter 'key' should not be null."); - } - } - - /** - * Registers a plugin in a project pom - * <p/> - * <p>Adds the plugin if it does not exist or amend its version if it does exist and specified</p> - * - * @param pom the project pom - * @param groupId the plugin group id - * @param artifactId the plugin artifact id - * @param version the plugin version - * @param overrideVersion whether to override the version if the plugin is already registered - * @return the registered plugin - */ - public static MavenPlugin registerPlugin(MavenProject pom, String groupId, String artifactId, String version, boolean overrideVersion) { - MavenPlugin plugin = getPlugin(pom, groupId, artifactId); - if (plugin == null) { - plugin = new MavenPlugin(groupId, artifactId, version); - - } else if (overrideVersion) { - plugin.setVersion(version); - } - - // remove from pom - unregisterPlugin(pom, groupId, artifactId); - - // register - pom.getBuild().addPlugin(plugin.getPlugin()); - - return plugin; - } - - /** - * Returns a plugin from a pom based on its group id and artifact id - * <p/> - * <p>It searches in the build section, then the reporting section and finally the pluginManagement section</p> - * - * @param pom the project pom - * @param groupId the plugin group id - * @param artifactId the plugin artifact id - * @return the plugin if it exists, null otherwise - */ - public static MavenPlugin getPlugin(MavenProject pom, String groupId, String artifactId) { - if (pom == null) { - return null; - } - // look for plugin in <build> section - Plugin plugin = null; - if (pom.getBuildPlugins() != null) { - plugin = getPlugin(pom.getBuildPlugins(), groupId, artifactId); - } - - // look for plugin in <report> section - if (plugin == null && pom.getReportPlugins() != null) { - plugin = getReportPlugin(pom.getReportPlugins(), groupId, artifactId); - } - - // look for plugin in <pluginManagement> section - if (pom.getPluginManagement() != null) { - Plugin pluginManagement = getPlugin(pom.getPluginManagement().getPlugins(), groupId, artifactId); - if (plugin == null) { - plugin = pluginManagement; - - } else if (pluginManagement != null) { - if (pluginManagement.getConfiguration() != null) { - if (plugin.getConfiguration() == null) { - plugin.setConfiguration(pluginManagement.getConfiguration()); - } else { - Xpp3Dom.mergeXpp3Dom((Xpp3Dom) plugin.getConfiguration(), (Xpp3Dom) pluginManagement.getConfiguration()); - } - } - if (plugin.getDependencies() == null && pluginManagement.getDependencies() != null) { - plugin.setDependencies(pluginManagement.getDependencies()); - } - if (plugin.getVersion() == null) { - plugin.setVersion(pluginManagement.getVersion()); - } - } - } - - if (plugin != null) { - return new MavenPlugin(plugin); - } - return null; - } - - private static Plugin getPlugin(Collection<Plugin> plugins, String groupId, String artifactId) { - if (plugins == null) { - return null; - } - - for (Plugin plugin : plugins) { - if (MavenUtils.equals(plugin, groupId, artifactId)) { - return plugin; - } - } - return null; - } - - private static Plugin getReportPlugin(Collection<ReportPlugin> plugins, String groupId, String artifactId) { - if (plugins == null) { - return null; - } - - for (ReportPlugin plugin : plugins) { - if (MavenUtils.equals(plugin, groupId, artifactId)) { - return cloneReportPluginToPlugin(plugin); - } - } - return null; - } - - private static Plugin cloneReportPluginToPlugin(ReportPlugin reportPlugin) { - Plugin plugin = new Plugin(); - plugin.setGroupId(reportPlugin.getGroupId()); - plugin.setArtifactId(reportPlugin.getArtifactId()); - plugin.setVersion(reportPlugin.getVersion()); - plugin.setConfiguration(reportPlugin.getConfiguration()); - return plugin; - } - - private static void unregisterPlugin(MavenProject pom, String groupId, String artifactId) { - if (pom.getPluginManagement() != null && pom.getPluginManagement().getPlugins() != null) { - unregisterPlugin(pom.getPluginManagement().getPlugins(), groupId, artifactId); - } - List plugins = pom.getBuildPlugins(); - if (plugins != null) { - unregisterPlugin(plugins, groupId, artifactId); - } - plugins = pom.getReportPlugins(); - if (plugins != null) { - unregisterReportPlugin(plugins, groupId, artifactId); - } - } - - private static void unregisterPlugin(List<Plugin> plugins, String groupId, String artifactId) { - for (Iterator<Plugin> iterator = plugins.iterator(); iterator.hasNext();) { - Plugin p = iterator.next(); - if (MavenUtils.equals(p, groupId, artifactId)) { - iterator.remove(); - } - } - } - - private static void unregisterReportPlugin(List<ReportPlugin> plugins, String groupId, String artifactId) { - for (Iterator<ReportPlugin> iterator = plugins.iterator(); iterator.hasNext();) { - ReportPlugin p = iterator.next(); - if (MavenUtils.equals(p, groupId, artifactId)) { - iterator.remove(); - } - } - } - - @Override - public String toString() { - return new ToStringBuilder(this) - .append("groupId", plugin.getGroupId()) - .append("artifactId", plugin.getArtifactId()) - .append("version", plugin.getVersion()) - .toString(); - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenSurefireUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenSurefireUtils.java deleted file mode 100644 index fed72d6f041..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenSurefireUtils.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.api.batch.maven; - -import org.sonar.api.resources.Project; - -/** - * @since 1.10 - * @deprecated since 4.5 we don't want any dependency on Maven anymore - */ -@Deprecated -public final class MavenSurefireUtils { - - public static final String GROUP_ID = MavenUtils.GROUP_ID_APACHE_MAVEN; - public static final String ARTIFACT_ID = "maven-surefire-plugin"; - public static final String VERSION = "2.4.3"; - - private MavenSurefireUtils() { - } - - /** - * Configures the project POM with base required surefire settings - * - * @param project the project currently analyzed - * @return the configured surefire MavenPlugin object instance, cannot be null - */ - public static MavenPlugin configure(Project project) { - MavenPlugin surefire = MavenPlugin.registerPlugin(project.getPom(), GROUP_ID, ARTIFACT_ID, VERSION, false); - surefire.setParameter("disableXmlReport", "false"); - surefire.setParameter("testFailureIgnore", "true"); - return surefire; - } - -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenUtils.java deleted file mode 100644 index 655edcdbecb..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenUtils.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.api.batch.maven; - -import org.apache.commons.lang.StringUtils; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.ReportPlugin; -import org.apache.maven.project.MavenProject; -import org.sonar.api.utils.log.Loggers; - -import java.nio.charset.Charset; -import java.util.Collection; - -/** - * An utility class to manipulate Maven concepts - * - * @since 1.10 - * @deprecated since 4.5 we don't want any dependency on Maven anymore - */ -@Deprecated -public final class MavenUtils { - - private static final String MAVEN_COMPILER_PLUGIN = "maven-compiler-plugin"; - public static final String GROUP_ID_APACHE_MAVEN = "org.apache.maven.plugins"; - public static final String GROUP_ID_CODEHAUS_MOJO = "org.codehaus.mojo"; - - private MavenUtils() { - // utility class with only static methods - } - - /** - * Returns the version of Java used by the maven compiler plugin - * - * @param pom the project pom - * @return the java version - */ - public static String getJavaVersion(MavenProject pom) { - MavenPlugin compilerPlugin = MavenPlugin.getPlugin(pom, GROUP_ID_APACHE_MAVEN, MAVEN_COMPILER_PLUGIN); - if (compilerPlugin != null) { - return compilerPlugin.getParameter("target"); - } - return null; - } - - public static String getJavaSourceVersion(MavenProject pom) { - MavenPlugin compilerPlugin = MavenPlugin.getPlugin(pom, GROUP_ID_APACHE_MAVEN, MAVEN_COMPILER_PLUGIN); - if (compilerPlugin != null) { - return compilerPlugin.getParameter("source"); - } - return null; - } - - /** - * Queries a collection of plugins based on a group id and an artifact id and returns the plugin if it exists - * - * @param plugins the plugins collection - * @param groupId the group id - * @param artifactId the artifact id - * @return the corresponding plugin if it exists, null otherwise - */ - public static Plugin getPlugin(Collection<Plugin> plugins, String groupId, String artifactId) { - if (plugins != null) { - for (Plugin plugin : plugins) { - if (equals(plugin, groupId, artifactId)) { - return plugin; - } - } - } - return null; - } - - /** - * Tests whether a plugin has got a given artifact id and group id - * - * @param plugin the plugin to test - * @param groupId the group id - * @param artifactId the artifact id - * @return whether the plugin has got group + artifact ids - */ - public static boolean equals(Plugin plugin, String groupId, String artifactId) { - if (plugin != null && plugin.getArtifactId().equals(artifactId)) { - if (plugin.getGroupId() == null) { - return groupId == null || groupId.equals(MavenUtils.GROUP_ID_APACHE_MAVEN) || groupId.equals(MavenUtils.GROUP_ID_CODEHAUS_MOJO); - } - return plugin.getGroupId().equals(groupId); - } - return false; - } - - /** - * Tests whether a ReportPlugin has got a given artifact id and group id - * - * @param plugin the ReportPlugin to test - * @param groupId the group id - * @param artifactId the artifact id - * @return whether the ReportPlugin has got group + artifact ids - */ - public static boolean equals(ReportPlugin plugin, String groupId, String artifactId) { - if (plugin != null && plugin.getArtifactId().equals(artifactId)) { - if (plugin.getGroupId() == null) { - return groupId == null || groupId.equals(MavenUtils.GROUP_ID_APACHE_MAVEN) || groupId.equals(MavenUtils.GROUP_ID_CODEHAUS_MOJO); - } - return plugin.getGroupId().equals(groupId); - } - return false; - } - - /** - * @return source encoding - */ - public static String getSourceEncoding(MavenProject pom) { - return pom.getProperties().getProperty("project.build.sourceEncoding"); - } - - /** - * Returns the charset of a pom - * - * @param pom the project pom - * @return the charset - */ - public static Charset getSourceCharset(MavenProject pom) { - String encoding = getSourceEncoding(pom); - if (StringUtils.isNotEmpty(encoding)) { - try { - return Charset.forName(encoding); - - } catch (Exception e) { - Loggers.get(MavenUtils.class).warn("Can not get project charset", e); - } - } - return Charset.defaultCharset(); - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java index 4063ed47712..5c083a107cd 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java @@ -19,21 +19,18 @@ */ package org.sonar.api.resources; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.maven.project.MavenProject; import org.sonar.api.CoreProperties; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.component.Component; import org.sonar.api.config.Settings; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - /** * A class that manipulates Projects in the Sonar way. * @@ -74,12 +71,10 @@ public class Project extends Resource implements Component { } } - private MavenProject pom; private String branch; private ProjectFileSystem fileSystem; private String name; private String description; - private String packaging; private Language language; private Date analysisDate; private AnalysisType analysisType; @@ -122,23 +117,6 @@ public class Project extends Resource implements Component { return this; } - /** - * For internal use only. - */ - public final Project setPom(MavenProject pom) { - this.pom = pom; - return this; - } - - /** - * @return the project's packaging - * @deprecated in 2.8. See http://jira.sonarsource.com/browse/SONAR-2341 - */ - @Deprecated - public String getPackaging() { - return packaging; - } - @Override public String getName() { return name; @@ -171,17 +149,6 @@ public class Project extends Resource implements Component { } /** - * For internal use only. - * - * @deprecated in 2.8. See http://jira.sonarsource.com/browse/SONAR-2341 - */ - @Deprecated - public Project setPackaging(String packaging) { - this.packaging = packaging; - return this; - } - - /** * @return whether the current project is root project */ public boolean isRoot() { @@ -393,32 +360,6 @@ public class Project extends Resource implements Component { return this; } - /** - * @deprecated since 2.5. See http://jira.sonarsource.com/browse/SONAR-2011 - */ - @Deprecated - public String getGroupId() { - return pom.getGroupId(); - } - - /** - * @deprecated since 2.5. See http://jira.sonarsource.com/browse/SONAR-2011 - */ - @Deprecated - public String getArtifactId() { - return pom.getArtifactId(); - } - - /** - * @return the underlying Maven project - * @deprecated since 2.5. See http://jira.sonarsource.com/browse/SONAR-2011 , - * MavenProject can be retrieved as an IoC dependency - */ - @Deprecated - public MavenProject getPom() { - return pom; - } - public static Project createFromMavenIds(String groupId, String artifactId) { return createFromMavenIds(groupId, artifactId, null); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenPluginTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenPluginTest.java deleted file mode 100644 index 1d6235f0866..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenPluginTest.java +++ /dev/null @@ -1,305 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.api.batch.maven; - -import org.apache.maven.model.Plugin; -import org.apache.maven.project.MavenProject; -import org.junit.Before; -import org.junit.Test; -import org.sonar.api.test.MavenTestUtils; - -import static org.assertj.core.api.Assertions.assertThat; - - -public class MavenPluginTest { - - private MavenPlugin fakePlugin; - - @Before - public void initPlugin() { - fakePlugin = new MavenPlugin("foo", "bar", "1.0"); - } - - @Test - public void getConfigurationXmlNode() { - assertThat(fakePlugin.getConfigurationXmlNode()).isNotNull(); - assertThat(fakePlugin.getConfigurationXmlNode().getName()).isEqualTo("configuration"); - } - - @Test - public void removeParameters() { - fakePlugin - .setParameter("foo", "bar") - .setParameter("hello", "world") - .removeParameters(); - - assertThat(fakePlugin.getParameter("foo")).isNull(); - assertThat(fakePlugin.getParameter("hello")).isNull(); - assertThat(fakePlugin.hasConfiguration()).isFalse(); - } - - @Test - public void shouldWriteAndReadSimpleConfiguration() { - fakePlugin.setParameter("abc", "test"); - assertThat(fakePlugin.getParameter("abc")).isEqualTo("test"); - } - - @Test - public void shouldWriteAndReadComplexConfiguration() { - fakePlugin.setParameter("abc/def/ghi", "test"); - assertThat(fakePlugin.getParameter("abc/def/ghi")).isEqualTo("test"); - } - - @Test - public void shouldReturnNullWhenChildNotFound() { - assertThat(fakePlugin.getParameter("abc/def/ghi")).isNull(); - } - - @Test(expected = IllegalArgumentException.class) - public void getChildValueShouldThrowExceptionWhenKeyIsNull() { - fakePlugin.getParameter(null); - } - - @Test(expected = IllegalArgumentException.class) - public void setChildValueShouldThrowExceptionWhenKeyIsNull() { - fakePlugin.setParameter(null, null); - } - - @Test - public void shouldRemoveParameter() { - fakePlugin.setParameter("abc", "1"); - assertThat(fakePlugin.getParameter("abc")).isNotNull(); - - fakePlugin.removeParameter("abc"); - assertThat(fakePlugin.getParameter("abc")).isNull(); - } - - @Test - public void shouldRemoveNestedParameter() { - fakePlugin.setParameter("abc/def", "1"); - assertThat(fakePlugin.getParameter("abc/def")).isNotNull(); - - fakePlugin.removeParameter("abc/def"); - - assertThat(fakePlugin.getParameter("abc/def")).isNull(); - } - - @Test - public void shouldRemoveNestedParameterButLeaveTheParent() { - fakePlugin.setParameter("abc/x", "1"); - fakePlugin.setParameter("abc/y", "2"); - - fakePlugin.removeParameter("abc/x"); - - assertThat(fakePlugin.getParameter("abc/y")).isNotNull(); - } - - @Test - public void shouldRemoveUnfoundChildWithoutError() { - fakePlugin.removeParameter("abc/def"); - } - - - @Test - public void shouldSetParameter() { - fakePlugin.addParameter("exclude", "abc"); - assertThat(fakePlugin.getParameter("exclude")).isEqualTo("abc"); - assertThat(fakePlugin.getParameters("exclude")).containsOnly("abc"); - } - - @Test - public void shouldOverrideNestedParameter() { - fakePlugin.setParameter("excludes/exclude", "abc"); - fakePlugin.setParameter("excludes/exclude", "overridden"); - assertThat(fakePlugin.getParameter("excludes/exclude")).isEqualTo("overridden"); - assertThat(fakePlugin.getParameters("excludes/exclude")).containsOnly("overridden"); - } - - @Test - public void shouldOverriddeParameter() { - fakePlugin.setParameter("exclude", "abc"); - fakePlugin.setParameter("exclude", "overridden"); - assertThat(fakePlugin.getParameter("exclude")).isEqualTo("overridden"); - assertThat(fakePlugin.getParameters("exclude")).containsOnly("overridden"); - } - - @Test - public void shouldAddNestedParameter() { - fakePlugin.addParameter("excludes/exclude", "abc"); - assertThat(fakePlugin.getParameter("excludes/exclude")).isEqualTo("abc"); - assertThat(fakePlugin.getParameters("excludes/exclude")).containsOnly("abc"); - } - - @Test - public void shouldAddManyValuesToTheSameParameter() { - fakePlugin.addParameter("excludes/exclude", "abc"); - fakePlugin.addParameter("excludes/exclude", "def"); - assertThat(fakePlugin.getParameters("excludes/exclude")).containsOnly("abc", "def"); - } - - @Test - public void defaultParameterIndexIsZero() { - fakePlugin.addParameter("items/item/entry", "value1"); - fakePlugin.addParameter("items/item/entry", "value2"); - - assertThat(fakePlugin.getParameters("items/item/entry")).containsOnly("value1", "value2"); - assertThat(fakePlugin.getParameters("items/item[0]/entry")).containsOnly("value1", "value2"); - } - - - @Test - public void addIndexedParameters() { - fakePlugin.addParameter("items/item[0]/entry", "value1"); - fakePlugin.addParameter("items/item[1]/entry", "value2"); - - assertThat(fakePlugin.getParameter("items/item[0]/entry")).isEqualTo("value1"); - assertThat(fakePlugin.getParameters("items/item[0]/entry")).containsOnly("value1"); - - assertThat(fakePlugin.getParameter("items/item[1]/entry")).isEqualTo("value2"); - assertThat(fakePlugin.getParameters("items/item[1]/entry")).containsOnly("value2"); - - //ensure that indexes aren't serialized to real configuration - assertThat(fakePlugin.getPlugin().getConfiguration().toString()).doesNotContain("item[0]"); - assertThat(fakePlugin.getPlugin().getConfiguration().toString()).doesNotContain("item[1]"); - } - - @Test - public void removeIndexedParameter() { - fakePlugin.addParameter("items/item[0]/entry", "value1"); - fakePlugin.addParameter("items/item[1]/entry", "value2"); - - fakePlugin.removeParameter("items/item[1]"); - fakePlugin.removeParameter("items/notExists"); - - assertThat(fakePlugin.getParameter("items/item[0]/entry")).isNotNull(); - assertThat(fakePlugin.getParameter("items/item[1]/entry")).isNull(); - assertThat(fakePlugin.getParameter("items/notExists")).isNull(); - } - - @Test - public void registerNewPlugin() { - MavenProject pom = MavenTestUtils.loadPom(getClass(), "registerNewPlugin.xml"); - MavenPlugin mavenPlugin = MavenPlugin.registerPlugin(pom, "mygroup", "my.artifact", "1.0", true); - - assertThat(mavenPlugin).isNotNull(); - Plugin plugin = MavenUtils.getPlugin(pom.getBuildPlugins(), "mygroup", "my.artifact"); - assertThat(plugin).isNotNull(); - assertThat(plugin.getVersion()).isEqualTo("1.0"); - } - - @Test - public void overridePluginManagementSection() { - MavenProject pom = MavenTestUtils.loadPom(getClass(), "overridePluginManagementSection.xml"); - MavenPlugin mavenPlugin = MavenPlugin.registerPlugin(pom, "mygroup", "my.artifact", "1.0", true); - assertThat(mavenPlugin).isNotNull(); - - Plugin plugin = MavenUtils.getPlugin(pom.getBuildPlugins(), "mygroup", "my.artifact"); - assertThat(plugin).isNotNull(); - assertThat(plugin.getVersion()).isEqualTo("1.0"); - - Plugin pluginManagement = MavenUtils.getPlugin(pom.getPluginManagement().getPlugins(), "mygroup", "my.artifact"); - assertThat(pluginManagement).isNull(); - } - - @Test - public void doNotOverrideVersionFromPluginManagementSection() { - MavenProject pom = MavenTestUtils.loadPom(getClass(), "overridePluginManagementSection.xml"); - MavenPlugin mavenPlugin = MavenPlugin.registerPlugin(pom, "mygroup", "my.artifact", "1.0", false); - assertThat(mavenPlugin).isNotNull(); - - Plugin plugin = MavenUtils.getPlugin(pom.getBuildPlugins(), "mygroup", "my.artifact"); - assertThat(plugin).isNotNull(); - assertThat(plugin.getVersion()).isEqualTo("0.9"); - - Plugin pluginManagement = MavenUtils.getPlugin(pom.getPluginManagement().getPlugins(), "mygroup", "my.artifact"); - assertThat(pluginManagement).isNull(); - } - - @Test - public void keepPluginManagementDependencies() { - MavenProject pom = MavenTestUtils.loadPom(getClass(), "keepPluginManagementDependencies.xml"); - MavenPlugin mavenPlugin = MavenPlugin.registerPlugin(pom, "mygroup", "my.artifact", "1.0", false); - assertThat(mavenPlugin).isNotNull(); - - Plugin plugin = MavenUtils.getPlugin(pom.getBuildPlugins(), "mygroup", "my.artifact"); - assertThat(plugin).isNotNull(); - assertThat(plugin.getVersion()).isEqualTo("0.9"); - assertThat(plugin.getDependencies().size()).isEqualTo(1); - } - - @Test - public void keepPluginDependencies() { - MavenProject pom = MavenTestUtils.loadPom(getClass(), "keepPluginDependencies.xml"); - MavenPlugin mavenPlugin = MavenPlugin.registerPlugin(pom, "mygroup", "my.artifact", "1.0", false); - assertThat(mavenPlugin).isNotNull(); - - Plugin plugin = MavenUtils.getPlugin(pom.getBuildPlugins(), "mygroup", "my.artifact"); - assertThat(plugin).isNotNull(); - assertThat(plugin.getVersion()).isEqualTo("0.9"); - assertThat(plugin.getDependencies().size()).isEqualTo(1); - } - - @Test - public void mergeSettings() { - MavenProject pom = MavenTestUtils.loadPom(getClass(), "mergeSettings.xml"); - MavenPlugin.registerPlugin(pom, "mygroup", "my.artifact", "1.0", false); - - MavenPlugin plugin = MavenPlugin.getPlugin(pom, "mygroup", "my.artifact"); - assertThat(plugin).isNotNull(); - assertThat(plugin.getPlugin().getVersion()).isEqualTo("0.9"); - assertThat(plugin.getParameter("foo")).isEqualTo("bar"); - } - - @Test - public void overrideVersionFromPluginManagement() { - MavenProject pom = MavenTestUtils.loadPom(getClass(), "overrideVersionFromPluginManagement.xml"); - MavenPlugin.registerPlugin(pom, "mygroup", "my.artifact", "1.0", true); - - MavenPlugin plugin = MavenPlugin.getPlugin(pom, "mygroup", "my.artifact"); - assertThat(plugin).isNotNull(); - assertThat(plugin.getPlugin().getVersion()).isEqualTo("1.0"); - assertThat(plugin.getParameter("foo")).isEqualTo("bar"); - } - - @Test - public void overrideVersion() { - MavenProject pom = MavenTestUtils.loadPom(getClass(), "overrideVersion.xml"); - MavenPlugin.registerPlugin(pom, "mygroup", "my.artifact", "1.0", true); - - MavenPlugin plugin = MavenPlugin.getPlugin(pom, "mygroup", "my.artifact"); - assertThat(plugin).isNotNull(); - assertThat(plugin.getPlugin().getVersion()).isEqualTo("1.0"); - assertThat(plugin.getParameter("foo")).isEqualTo("bar"); - } - - @Test - public void getConfigurationFromReport() { - MavenProject pom = MavenTestUtils.loadPom(getClass(), "getConfigurationFromReport.xml"); - MavenPlugin.registerPlugin(pom, "mygroup", "my.artifact", "1.0", true); - - assertThat(pom.getBuildPlugins().size()).isEqualTo(1); - assertThat(pom.getReportPlugins().size()).isEqualTo(0); - - MavenPlugin plugin = MavenPlugin.getPlugin(pom, "mygroup", "my.artifact"); - assertThat(plugin).isNotNull(); - assertThat(plugin.getPlugin().getVersion()).isEqualTo("1.0"); - assertThat(plugin.getParameter("foo")).isEqualTo("bar"); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenSurefireUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenSurefireUtilsTest.java deleted file mode 100644 index 4f597c7e1da..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenSurefireUtilsTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.api.batch.maven; - -import static org.junit.Assert.assertEquals; -import org.junit.Test; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import org.sonar.api.resources.Project; -import org.sonar.api.test.MavenTestUtils; - -public class MavenSurefireUtilsTest { - - @Test - public void shouldConfigureProject() { - Project prj = mock(Project.class); - when(prj.getPom()).thenReturn(MavenTestUtils.loadPom("/org/sonar/api/batch/maven/MavenSurefireUtilsTest/MavenPom.xml")); - - MavenPlugin configuredPlugin = MavenSurefireUtils.configure(prj); - assertEquals("true", configuredPlugin.getParameter("testFailureIgnore")); - assertEquals("false", configuredPlugin.getParameter("disableXmlReport")); - assertEquals(MavenSurefireUtils.VERSION, configuredPlugin.getPlugin().getVersion()); - } - -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenUtilsTest.java deleted file mode 100644 index 5f2f465bc2b..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenUtilsTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.api.batch.maven; - -import org.apache.maven.project.MavenProject; -import org.junit.Before; -import org.junit.Test; -import org.sonar.api.test.MavenTestUtils; - -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - -public class MavenUtilsTest { - private MavenProject pom; - - @Before - public void setUp() { - pom = MavenTestUtils.loadPom("/org/sonar/api/batch/maven/MavenPom.xml"); - } - - @Test - public void getJavaVersion() { - MavenProject pom = MavenTestUtils.loadPom(getClass(), "getJavaVersion.xml"); - assertThat(MavenUtils.getJavaVersion(pom), is("1.4")); - } - - @Test - public void getJavaVersionFromPluginManagement() { - MavenProject pom = MavenTestUtils.loadPom(getClass(), "getJavaVersionFromPluginManagement.xml"); - assertThat(MavenUtils.getJavaVersion(pom), is("1.4")); - } - - @Test - public void testDefaultSourceEncoding() { - assertEquals(MavenUtils.getSourceCharset(pom), Charset.defaultCharset()); - } - - @Test - public void testSourceEncoding() { - MavenProject pom = MavenTestUtils.loadPom("/org/sonar/api/batch/maven/MavenPomWithSourceEncoding.xml"); - assertEquals(MavenUtils.getSourceCharset(pom), StandardCharsets.UTF_16); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ProjectTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ProjectTest.java index c91b964dd61..a1f531b1d03 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ProjectTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ProjectTest.java @@ -20,23 +20,12 @@ package org.sonar.api.resources; import org.junit.Test; -import org.sonar.api.test.MavenTestUtils; import static org.assertj.core.api.Assertions.assertThat; public class ProjectTest { @Test - public void equalsProject() { - Project project1 = MavenTestUtils.loadProjectFromPom(getClass(), "equalsProject/pom.xml"); - Project project2 = MavenTestUtils.loadProjectFromPom(getClass(), "equalsProject/pom.xml"); - - assertThat(project1).isEqualTo(project2); - assertThat(project1).isNotEqualTo("foo:bar"); - assertThat(project1.hashCode()).isEqualTo(project2.hashCode()); - } - - @Test public void effectiveKeyShouldEqualKey() { assertThat(new Project("my:project").getEffectiveKey()).isEqualTo("my:project"); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/MavenTestUtils.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/MavenTestUtils.java deleted file mode 100644 index 6050c140bb1..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/test/MavenTestUtils.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.api.test; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.apache.maven.model.Model; -import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.apache.maven.project.MavenProject; -import org.sonar.api.batch.maven.MavenUtils; -import org.sonar.api.resources.InputFile; -import org.sonar.api.resources.Language; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.ProjectFileSystem; -import org.sonar.api.resources.Resource; -import org.sonar.api.scan.filesystem.PathResolver; -import org.sonar.api.utils.SonarException; - -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public final class MavenTestUtils { - - public static MavenProject loadPom(Class clazz, String path) { - String fullpath = "/" + clazz.getName().replaceAll("\\.", "/") + "/" + path; - return loadPom(fullpath); - } - - public static MavenProject loadPom(String pomUrlInClasspath) { - FileReader fileReader = null; - try { - File pomFile = new File(MavenTestUtils.class.getResource(pomUrlInClasspath).toURI()); - MavenXpp3Reader pomReader = new MavenXpp3Reader(); - fileReader = new FileReader(pomFile); - Model model = pomReader.read(fileReader); - MavenProject project = new MavenProject(model); - project.setFile(pomFile); - project.getBuild().setDirectory(pomFile.getParentFile().getPath()); - project.addCompileSourceRoot(pomFile.getParentFile().getPath() + "/src/main/java"); - project.addTestCompileSourceRoot(pomFile.getParentFile().getPath() + "/src/test/java"); - return project; - } catch (Exception e) { - throw new SonarException("Failed to read Maven project file : " + pomUrlInClasspath, e); - - } finally { - IOUtils.closeQuietly(fileReader); - } - } - - 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; - } - - public static MavenProject mockPom(String packaging) { - MavenProject mavenProject = mock(MavenProject.class); - when(mavenProject.getPackaging()).thenReturn(packaging); - return mavenProject; - } - - static class MavenModuleFileSystem implements ProjectFileSystem { - private MavenProject pom; - - MavenModuleFileSystem(MavenProject pom) { - this.pom = pom; - } - - public Charset getSourceCharset() { - return Charset.forName(MavenUtils.getSourceEncoding(pom)); - } - - public File getBasedir() { - return pom.getBasedir(); - } - - public File getBuildDir() { - return new File(pom.getBuild().getDirectory()); - } - - public File getBuildOutputDir() { - return new File(pom.getBuild().getOutputDirectory()); - } - - public List<File> getSourceDirs() { - return Arrays.asList(new File(pom.getBuild().getSourceDirectory())); - } - - public ProjectFileSystem addSourceDir(File dir) { - throw new UnsupportedOperationException(); - } - - public List<File> getTestDirs() { - return null; - } - - public ProjectFileSystem addTestDir(File dir) { - throw new UnsupportedOperationException(); - } - - public File getReportOutputDir() { - return null; - } - - public File getSonarWorkingDirectory() { - File dir = new File(getBuildDir(), "sonar"); - try { - FileUtils.forceMkdir(dir); - } catch (IOException e) { - throw new IllegalStateException(e); - } - return dir; - } - - public File resolvePath(String path) { - return new PathResolver().relativeFile(getBasedir(), path); - } - - public List<File> getSourceFiles(Language... langs) { - return new ArrayList(FileUtils.listFiles(getSourceDirs().get(0), new String[] {"java"}, true)); - } - - public List<File> getJavaSourceFiles() { - return getSourceFiles(); - } - - public boolean hasJavaSourceFiles() { - return !getJavaSourceFiles().isEmpty(); - } - - public List<File> getTestFiles(Language... langs) { - return new ArrayList(FileUtils.listFiles(getTestDirs().get(0), new String[] {"java"}, true)); - } - - public boolean hasTestFiles(Language lang) { - return !getTestFiles(lang).isEmpty(); - } - - public File writeToWorkingDirectory(String content, String fileName) throws IOException { - throw new UnsupportedOperationException(); - } - - public File getFileFromBuildDirectory(String filename) { - throw new UnsupportedOperationException(); - } - - public Resource toResource(File file) { - throw new UnsupportedOperationException(); - } - - public List<InputFile> mainFiles(String... langs) { - throw new UnsupportedOperationException(); - } - - public List<InputFile> testFiles(String... langs) { - throw new UnsupportedOperationException(); - } - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/ProjectTestBuilder.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/ProjectTestBuilder.java deleted file mode 100644 index 9cb17d171df..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/test/ProjectTestBuilder.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.api.test; - -import org.apache.maven.project.MavenProject; -import org.sonar.api.resources.Project; - -import static org.mockito.Mockito.when; - -public class ProjectTestBuilder { - - private MavenProject pom = MavenTestUtils.mockPom("jar"); - - public Project build() { - when(pom.getGroupId()).thenReturn("mygroup"); - when(pom.getArtifactId()).thenReturn("myartifact"); - when(pom.isExecutionRoot()).thenReturn(true); - return new Project("mygroup:myartifact").setPom(pom); - } -} diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/hidden-files/pom.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/hidden-files/pom.xml deleted file mode 100644 index f82dd82940f..00000000000 --- a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/hidden-files/pom.xml +++ /dev/null @@ -1,7 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>foo</groupId> - <artifactId>foo</artifactId> - -</project>
\ No newline at end of file diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/hidden-files/src/main/java/.hidden b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/hidden-files/src/main/java/.hidden deleted file mode 100644 index a0c8a07aad5..00000000000 --- a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/hidden-files/src/main/java/.hidden +++ /dev/null @@ -1 +0,0 @@ -this is an hidden file
\ No newline at end of file diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/hidden-files/src/main/java/.hiddendir/file_in_hidden_dir.txt b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/hidden-files/src/main/java/.hiddendir/file_in_hidden_dir.txt deleted file mode 100644 index c246937debd..00000000000 --- a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/hidden-files/src/main/java/.hiddendir/file_in_hidden_dir.txt +++ /dev/null @@ -1 +0,0 @@ -file in hidden dir
\ No newline at end of file diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/hidden-files/src/main/java/foo.sql b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/hidden-files/src/main/java/foo.sql deleted file mode 100644 index e69de29bb2d..00000000000 --- a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/hidden-files/src/main/java/foo.sql +++ /dev/null diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/japanese-project/pom.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/japanese-project/pom.xml deleted file mode 100644 index 6fee0588cdb..00000000000 --- a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/japanese-project/pom.xml +++ /dev/null @@ -1,26 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>foo</groupId> - <artifactId>foo</artifactId> - <packaging>jar</packaging> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.5</source> - <target>1.5</target> - <encoding>Shift_JIS</encoding> - </configuration> - </plugin> - </plugins> - </build> - - <properties> - <project.build.sourceEncoding>Shift_JIS</project.build.sourceEncoding> - </properties> - -</project>
\ No newline at end of file diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/nonexistent-dirs/pom.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/nonexistent-dirs/pom.xml deleted file mode 100644 index f219368e824..00000000000 --- a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/nonexistent-dirs/pom.xml +++ /dev/null @@ -1,8 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>foo</groupId> - <artifactId>foo</artifactId> - <packaging>jar</packaging> - -</project>
\ No newline at end of file diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/nonexistent-dirs/src/main/java b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/nonexistent-dirs/src/main/java deleted file mode 100644 index e69de29bb2d..00000000000 --- a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/nonexistent-dirs/src/main/java +++ /dev/null diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample-with-different-suffixes/pom.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample-with-different-suffixes/pom.xml deleted file mode 100644 index c9de7e74d6e..00000000000 --- a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample-with-different-suffixes/pom.xml +++ /dev/null @@ -1,7 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>foo</groupId> - <artifactId>foo</artifactId> - <packaging>jar</packaging> -</project>
\ No newline at end of file diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample-with-different-suffixes/src/main/java/foo.c b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample-with-different-suffixes/src/main/java/foo.c deleted file mode 100644 index 953870a6684..00000000000 --- a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample-with-different-suffixes/src/main/java/foo.c +++ /dev/null @@ -1 +0,0 @@ -// some C code
\ No newline at end of file diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample-with-different-suffixes/src/main/java/foo.sql b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample-with-different-suffixes/src/main/java/foo.sql deleted file mode 100644 index 72e73020ee1..00000000000 --- a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample-with-different-suffixes/src/main/java/foo.sql +++ /dev/null @@ -1 +0,0 @@ -select * from foo;
\ No newline at end of file diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample/pom.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample/pom.xml deleted file mode 100644 index f219368e824..00000000000 --- a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample/pom.xml +++ /dev/null @@ -1,8 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>foo</groupId> - <artifactId>foo</artifactId> - <packaging>jar</packaging> - -</project>
\ No newline at end of file diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample/src/main/java/foo/Bar.java b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample/src/main/java/foo/Bar.java deleted file mode 100644 index ff23f5100d7..00000000000 --- a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample/src/main/java/foo/Bar.java +++ /dev/null @@ -1,4 +0,0 @@ -package foo; - -public class Bar { -} diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample/src/main/java/foo/Whizz.java b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample/src/main/java/foo/Whizz.java deleted file mode 100644 index a8723f69913..00000000000 --- a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample/src/main/java/foo/Whizz.java +++ /dev/null @@ -1,4 +0,0 @@ -package foo; - -public class Whizz { -} diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample/src/test/java/foo/BarTest.java b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample/src/test/java/foo/BarTest.java deleted file mode 100644 index 2c7957f737f..00000000000 --- a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/sample/src/test/java/foo/BarTest.java +++ /dev/null @@ -1,6 +0,0 @@ -package foo; - -import org.junit.Ignore; - -public abstract class BarTest { -} diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/ProjectTest/equalsProject/pom.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/ProjectTest/equalsProject/pom.xml deleted file mode 100644 index bf73bcf9737..00000000000 --- a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/ProjectTest/equalsProject/pom.xml +++ /dev/null @@ -1,8 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>foo</groupId> - <artifactId>bar</artifactId> - <packaging>jar</packaging> - -</project>
\ No newline at end of file diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/ProjectTest/keyContainsBranch/pom.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/ProjectTest/keyContainsBranch/pom.xml deleted file mode 100644 index be8fdaf72b2..00000000000 --- a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/ProjectTest/keyContainsBranch/pom.xml +++ /dev/null @@ -1,11 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>foo</groupId> - <artifactId>bar</artifactId> - <packaging>jar</packaging> - - <properties> - <sonar.branch>BRANCH-1.X</sonar.branch> - </properties> -</project>
\ No newline at end of file |