aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-02-10 00:17:18 +0100
committersimonbrandhof <simon.brandhof@gmail.com>2011-02-10 00:17:18 +0100
commit12c2ca81edccfdb8356f21ff231816b0338179ee (patch)
tree4f71e17bb88872a73788baabdbaddaf54844df73 /sonar-batch
parentbc4727a1de0102aad02876b6ab50128499623c16 (diff)
downloadsonarqube-12c2ca81edccfdb8356f21ff231816b0338179ee.tar.gz
sonarqube-12c2ca81edccfdb8356f21ff231816b0338179ee.zip
Improve code: fix some violations
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java9
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempDirectories.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java12
3 files changed, 15 insertions, 10 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java
index 6dbec54a2c7..add063534aa 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java
@@ -30,6 +30,7 @@ import org.sonar.api.measures.Measure;
import org.sonar.api.measures.Metric;
import org.sonar.api.measures.MetricFinder;
import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Resource;
import org.sonar.batch.index.DefaultIndex;
@@ -89,10 +90,14 @@ public class DefaultTimeMachine implements TimeMachine {
} else {
sb.append("SELECT s.createdAt, m.metricId, m.value ");
}
- sb.append(" FROM " + MeasureModel.class.getSimpleName() + " m, " + Snapshot.class.getSimpleName() + " s WHERE m.snapshotId=s.id AND s.resourceId=:resourceId AND s.status=:status AND m.characteristic IS NULL AND s.qualifier<>:lib");
+ sb.append(" FROM ")
+ .append(MeasureModel.class.getSimpleName())
+ .append(" m, ")
+ .append(Snapshot.class.getSimpleName())
+ .append(" s WHERE m.snapshotId=s.id AND s.resourceId=:resourceId AND s.status=:status AND m.characteristic IS NULL AND s.qualifier<>:lib");
params.put("resourceId", resource.getId());
params.put("status", Snapshot.STATUS_PROCESSED);
- params.put("lib", Project.QUALIFIER_LIB);
+ params.put("lib", Qualifiers.LIBRARY);
sb.append(" AND m.ruleId IS NULL AND m.rulePriority IS NULL ");
if (!metricIds.isEmpty()) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempDirectories.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempDirectories.java
index 7ae7f4026fb..f1ca7491db8 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempDirectories.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempDirectories.java
@@ -92,7 +92,9 @@ public final class TempDirectories {
// Deleting temp directory does not work on MS Windows and Sun JVM because URLClassLoader locks JARs and resources.
// The workaround is that sonar deletes orphans itself.
- rootDir.setLastModified(System.currentTimeMillis() - AGE_BEFORE_DELETION - 60 * 60 * 1000); // older than AGE_BEFORE_DELETION to be sure that the current dir is deleted on mac and linux.
+
+ // older than AGE_BEFORE_DELETION to be sure that the current dir is deleted on mac and linux.
+ rootDir.setLastModified(System.currentTimeMillis() - AGE_BEFORE_DELETION - 60 * 60 * 1000);
File[] directoriesToDelete = rootDir.getParentFile().listFiles((FileFilter) new AndFileFilter(Arrays.asList(
DirectoryFileFilter.DIRECTORY, new PrefixFileFilter(DIR_PREFIX), new AgeFileFilter(System.currentTimeMillis() - AGE_BEFORE_DELETION))));
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
index 0365c6c8b2f..fd72b491777 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
@@ -25,10 +25,7 @@ import org.apache.commons.lang.StringUtils;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Library;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.resources.ResourceUtils;
+import org.sonar.api.resources.*;
import org.sonar.api.utils.SonarException;
import javax.persistence.NonUniqueResultException;
@@ -151,7 +148,7 @@ public final class DefaultResourcePersister implements ResourcePersister {
// see http://jira.codehaus.org/browse/SONAR-1850
// The qualifier must be LIB, even if the resource is TRK, because this snapshot has no measures.
- snapshot.setQualifier(Resource.QUALIFIER_LIB);
+ snapshot.setQualifier(Qualifiers.LIBRARY);
snapshot = session.save(snapshot);
}
session.commit();
@@ -159,7 +156,8 @@ public final class DefaultResourcePersister implements ResourcePersister {
}
private Snapshot findLibrarySnapshot(Integer resourceId, String version) {
- Query query = session.createQuery("from " + Snapshot.class.getSimpleName() + " s WHERE s.resourceId=:resourceId AND s.version=:version AND s.scope=:scope AND s.qualifier<>:qualifier AND s.last=:last");
+ Query query = session.createQuery("from " + Snapshot.class.getSimpleName() +
+ " s WHERE s.resourceId=:resourceId AND s.version=:version AND s.scope=:scope AND s.qualifier<>:qualifier AND s.last=:last");
query.setParameter("resourceId", resourceId);
query.setParameter("version", version);
query.setParameter("scope", Resource.SCOPE_SET);
@@ -167,7 +165,7 @@ public final class DefaultResourcePersister implements ResourcePersister {
query.setParameter("last", Boolean.TRUE);
List<Snapshot> snapshots = query.getResultList();
if (snapshots.isEmpty()) {
- snapshots = session.getResults(Snapshot.class, "resourceId", resourceId, "version", version, "scope", Resource.SCOPE_SET, "qualifier", Resource.QUALIFIER_LIB);
+ snapshots = session.getResults(Snapshot.class, "resourceId", resourceId, "version", version, "scope", Scopes.PROJECT, "qualifier", Qualifiers.LIBRARY);
}
return (snapshots.isEmpty() ? null : snapshots.get(0));
}