From: simonbrandhof Date: Wed, 9 Feb 2011 23:17:18 +0000 (+0100) Subject: Improve code: fix some violations X-Git-Tag: 2.6~13 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=12c2ca81edccfdb8356f21ff231816b0338179ee;p=sonarqube.git Improve code: fix some violations --- diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java index 53b5f77f3a2..1408ac59902 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java @@ -59,8 +59,9 @@ public class NewViolationsDecorator implements Decorator { @DependedUpon public List generatesMetric() { - return Arrays.asList(CoreMetrics.NEW_VIOLATIONS, - CoreMetrics.NEW_BLOCKER_VIOLATIONS, CoreMetrics.NEW_CRITICAL_VIOLATIONS, CoreMetrics.NEW_MAJOR_VIOLATIONS, CoreMetrics.NEW_MINOR_VIOLATIONS, CoreMetrics.NEW_INFO_VIOLATIONS); + return Arrays.asList( + CoreMetrics.NEW_VIOLATIONS, CoreMetrics.NEW_BLOCKER_VIOLATIONS, CoreMetrics.NEW_CRITICAL_VIOLATIONS, + CoreMetrics.NEW_MAJOR_VIOLATIONS, CoreMetrics.NEW_MINOR_VIOLATIONS, CoreMetrics.NEW_INFO_VIOLATIONS); } public void decorate(Resource resource, DecoratorContext context) { 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 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)); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/TempFileUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/TempFileUtils.java index fc2a2401191..e30a69a9594 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/TempFileUtils.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/TempFileUtils.java @@ -34,7 +34,9 @@ public final class TempFileUtils { *
    *
  1. deleteOnExit() only deletes for normal JVM shutdowns, not crashes or killing the JVM process
  2. *
  3. deleteOnExit() only deletes on JVM shutdown - not good for long running server processes because 3 :
  4. - *
  5. The most evil of all - deleteOnExit() consumes memory for each temp file entry. If your process is running for months, or creates a lot of temp files in a short time, you consume memory and never release it until the JVM shuts down.
  6. + *
  7. The most evil of all - deleteOnExit() consumes memory for each temp file entry. If your process is running for months, + * or creates a lot of temp files in a short time, you consume memory and never release it until the JVM + * shuts down.
  8. *
*/ public static File createTempDirectory() throws IOException {