aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-01-20 15:05:21 +0300
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-01-20 16:49:40 +0300
commitfeb1afef7c9aac12f280185267b8fa77ad87c895 (patch)
tree3ef9dec6700bbdbc34d0eae7a02e971b4e2bcb07
parent1ab2475003835b71ff44b3652691c538059db699 (diff)
downloadsonarqube-feb1afef7c9aac12f280185267b8fa77ad87c895.tar.gz
sonarqube-feb1afef7c9aac12f280185267b8fa77ad87c895.zip
SONAR-2126: Change API to work with project
* Add natures and exclusions/inclusions to ProjectDirectory * Deprecate ProjectFileSystem and Project.getFileSystem() * Instead of interface ProjectDefinition provide class only for bootstrap of batch
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/DefaultProjectDefinition.java95
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectDefinition.java95
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/project/ProjectDefinition.java76
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/DefaultProjectDirectory.java (renamed from sonar-batch/src/main/java/org/sonar/batch/DefaultProjectDirectory.java)56
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/Natures.java18
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java5
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectDirectory.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/project/ProjectDirectory.java)19
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectFileSystem.java1
8 files changed, 168 insertions, 197 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectDefinition.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectDefinition.java
deleted file mode 100644
index 82e81da59bd..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectDefinition.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.batch;
-
-import com.google.common.collect.Lists;
-import org.apache.commons.configuration.Configuration;
-import org.sonar.api.project.ProjectDefinition;
-import org.sonar.api.project.ProjectDirectory;
-
-import java.io.File;
-import java.util.List;
-
-public class DefaultProjectDefinition implements ProjectDefinition {
-
- private String key;
- private Configuration configuration;
- private File sonarWorkingDirectory;
- private File basedir;
- private List<ProjectDirectory> dirs = Lists.newArrayList();
- private DefaultProjectDefinition parent;
- private List<ProjectDefinition> modules;
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-
- public Configuration getConfiguration() {
- return configuration;
- }
-
- public void setConfiguration(Configuration configuration) {
- this.configuration = configuration;
- }
-
- public File getSonarWorkingDirectory() {
- return sonarWorkingDirectory;
- }
-
- public void setSonarWorkingDirectory(File sonarWorkingDirectory) {
- this.sonarWorkingDirectory = sonarWorkingDirectory;
- }
-
- public File getBasedir() {
- return basedir;
- }
-
- public void setBasedir(File basedir) {
- this.basedir = basedir;
- }
-
- public List<ProjectDirectory> getDirs() {
- return dirs;
- }
-
- public void addDir(ProjectDirectory dir) {
- this.dirs.add(dir);
- }
-
- public ProjectDefinition getParent() {
- return parent;
- }
-
- public void setParent(DefaultProjectDefinition parent) {
- this.parent = parent;
- if (parent != null) {
- parent.modules.add(this);
- }
- }
-
- public List<ProjectDefinition> getModules() {
- return modules;
- }
-
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectDefinition.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectDefinition.java
new file mode 100644
index 00000000000..578ca9e4a16
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectDefinition.java
@@ -0,0 +1,95 @@
+package org.sonar.batch.bootstrap;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.configuration.Configuration;
+import org.sonar.api.resources.ProjectDirectory;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ * Defines project in a form suitable to bootstrap Sonar batch.
+ * We assume that project is just a set of configuration properties and directories.
+ * This is a part of bootstrap process, so we should take care about backward compatibility.
+ *
+ * @since 2.6
+ */
+public class ProjectDefinition {
+
+ private Configuration configuration;
+
+ private File workDir;
+ private File basedir;
+ private List<ProjectDirectory> dirs = Lists.newArrayList();
+
+ private ProjectDefinition parent;
+ private List<ProjectDefinition> modules;
+
+ /**
+ * @return project properties.
+ */
+ public Configuration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(Configuration configuration) {
+ this.configuration = configuration;
+ }
+
+ /**
+ * @return Sonar working directory for this project.
+ * It's "${project.build.directory}/sonar" ("${project.basedir}/target/sonar") for Maven projects.
+ */
+ public File getSonarWorkingDirectory() {
+ return workDir;
+ }
+
+ public void setSonarWorkingDirectory(File workDir) {
+ this.workDir = workDir;
+ }
+
+ /**
+ * @return project root directory.
+ * It's "${project.basedir}" for Maven projects.
+ */
+ public File getBasedir() {
+ return basedir;
+ }
+
+ public void setBasedir(File basedir) {
+ this.basedir = basedir;
+ }
+
+ /**
+ * @return project directories.
+ */
+ public List<ProjectDirectory> getDirs() {
+ return dirs;
+ }
+
+ public void addDir(ProjectDirectory dir) {
+ this.dirs.add(dir);
+ }
+
+ /**
+ * @return parent project.
+ */
+ public ProjectDefinition getParent() {
+ return parent;
+ }
+
+ public void setParent(ProjectDefinition parent) {
+ this.parent = parent;
+ if (parent != null) {
+ parent.modules.add(this);
+ }
+ }
+
+ /**
+ * @return list of sub-projects.
+ */
+ public List<ProjectDefinition> getModules() {
+ return modules;
+ }
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/project/ProjectDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/project/ProjectDefinition.java
deleted file mode 100644
index db076fe803d..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/project/ProjectDefinition.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.api.project;
-
-import org.apache.commons.configuration.Configuration;
-
-import java.io.File;
-import java.util.List;
-
-/**
- * Defines project in a form suitable for Sonar.
- * This is a part of bootstrap process, so we should take care about backward compatibility.
- * <p>
- * We assume that project is just a set of configuration properties and directories. And each project has unique key in format
- * "groupId:artifactId" (for example "org.codehaus.sonar:sonar").
- * </p>
- *
- * @since 2.6
- */
-public interface ProjectDefinition {
-
- /**
- * @return project key.
- */
- String getKey();
-
- /**
- * @return project properties.
- */
- Configuration getConfiguration();
-
- /**
- * @return Sonar working directory.
- * It's "${project.build.directory}/sonar" ("${project.basedir}/target/sonar") for Maven projects.
- */
- File getSonarWorkingDirectory();
-
- /**
- * @return project root directory.
- * It's "${project.basedir}" for Maven projects.
- */
- File getBasedir();
-
- /**
- * @return project directories.
- */
- List<ProjectDirectory> getDirs();
-
- /**
- * @return parent project.
- */
- ProjectDefinition getParent();
-
- /**
- * @return list of sub-projects.
- */
- List<ProjectDefinition> getModules();
-
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectDirectory.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/DefaultProjectDirectory.java
index 7c080531435..bdf4ba1a6bb 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectDirectory.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/DefaultProjectDirectory.java
@@ -17,9 +17,9 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.batch;
+package org.sonar.api.resources;
-import org.sonar.api.project.ProjectDirectory;
+import com.google.common.collect.Lists;
import java.io.File;
import java.util.Collections;
@@ -27,42 +27,72 @@ import java.util.List;
public class DefaultProjectDirectory implements ProjectDirectory {
- private Kind kind;
+ private String nature;
private File location;
private File outputLocation;
+ private List<String> inclusionPatterns;
+ private List<String> exclusionPatterns;
- public Kind getKind() {
- return kind;
+ public String getNature() {
+ return nature;
}
- public void setKind(Kind kind) {
- this.kind = kind;
+ public DefaultProjectDirectory setNature(String nature) {
+ this.nature = nature;
+ return this;
}
public File getLocation() {
return location;
}
- public void setLocation(File location) {
+ public DefaultProjectDirectory setLocation(File location) {
this.location = location;
+ return this;
}
public File getOutputLocation() {
return outputLocation;
}
- public void setOutputLocation(File outputLocation) {
+ public DefaultProjectDirectory setOutputLocation(File outputLocation) {
this.outputLocation = outputLocation;
+ return this;
}
public List<String> getInclusionPatterns() {
- // TODO see example in ProjectDirectory
- return Collections.emptyList();
+ if (inclusionPatterns == null) {
+ return Collections.emptyList();
+ }
+ return Collections.unmodifiableList(inclusionPatterns);
+ }
+
+ /**
+ * @param pattern Ant-like inclusion pattern
+ */
+ public DefaultProjectDirectory addInclusionPattern(String pattern) {
+ if (inclusionPatterns == null) {
+ inclusionPatterns = Lists.newArrayList();
+ }
+ inclusionPatterns.add(pattern);
+ return this;
}
public List<String> getExclusionPatterns() {
- // TODO see example in ProjectDirectory
- return Collections.emptyList();
+ if (exclusionPatterns == null) {
+ return Collections.emptyList();
+ }
+ return Collections.unmodifiableList(exclusionPatterns);
}
+ /**
+ * @param pattern Ant-like exclusion pattern
+ */
+ public DefaultProjectDirectory addExclusionPattern(String pattern) {
+ if (exclusionPatterns == null) {
+ exclusionPatterns = Lists.newArrayList();
+ }
+ exclusionPatterns.add(pattern);
+ return this;
+ }
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Natures.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Natures.java
new file mode 100644
index 00000000000..5b8f102fef6
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Natures.java
@@ -0,0 +1,18 @@
+package org.sonar.api.resources;
+
+/**
+ * @since 2.6
+ */
+public interface Natures {
+
+ /**
+ * Everything which relate to source code (for example "src/main/java" and "src/main/resources").
+ */
+ String MAIN = "MAIN";
+
+ /**
+ * Everything which relate to unit tests (for example "src/test/java" and "src/test/resources").
+ */
+ String TEST = "TEST";
+
+}
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 e4f14394dfa..11d403a7723 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
@@ -363,12 +363,17 @@ public class Project extends Resource {
return this;
}
+ /**
+ * @deprecated since 2.6. See http://jira.codehaus.org/browse/SONAR-2126
+ */
public ProjectFileSystem getFileSystem() {
return fileSystem;
}
/**
* For internal use only.
+ *
+ * @deprecated since 2.6. See http://jira.codehaus.org/browse/SONAR-2126
*/
public Project setFileSystem(ProjectFileSystem fs) {
this.fileSystem = fs;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/project/ProjectDirectory.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectDirectory.java
index d516a46b959..4b645a553ce 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/project/ProjectDirectory.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectDirectory.java
@@ -17,7 +17,8 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.api.project;
+package org.sonar.api.resources;
+
import java.io.File;
import java.util.List;
@@ -50,22 +51,14 @@ import java.util.List;
public interface ProjectDirectory {
/**
- * TODO We should find a more flexible way to specify kind.
- * Because actually this is just a logical division to be able to associate different quality profiles for different kinds of directories.
- * Imagine that we can have different rules for unit tests, integration tests, performance tests, UI tests and so on.
- * But seems that for now this enumeration would cover our needs.
- */
- public static enum Kind {
- SOURCES, RESOURCES, TESTS, TEST_RESOURCES
- }
-
- /**
- * @return kind of underlying files.
+ * @return nature of underlying files.
+ * @see Natures
*/
- Kind getKind();
+ String getNature();
/**
* @return location of files for compilation.
+ * In case of Java this would be directory with Java source files.
*/
File getLocation();
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectFileSystem.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectFileSystem.java
index d6ef7c3a0e6..9440b37daf7 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectFileSystem.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectFileSystem.java
@@ -26,6 +26,7 @@ import java.util.List;
/**
* @since 1.10
+ * @deprecated since 2.6
*/
public interface ProjectFileSystem {
/**