This repository has been archived by the owner on Aug 24, 2019. It is now read-only.
forked from octo-technology/sonar-objective-c
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
757 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/main/java/org/sonar/plugins/objectivec/complexity/LizardMeasurePersistor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Sonar Objective-C Plugin | ||
* Copyright (C) 2012 OCTO Technology, Backelite | ||
* dev@sonar.codehaus.org | ||
* | ||
* This program 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. | ||
* | ||
* This program 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 02 | ||
*/ | ||
package org.sonar.plugins.objectivec.complexity; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.sonar.api.batch.SensorContext; | ||
import org.sonar.api.batch.fs.FileSystem; | ||
import org.sonar.api.measures.Measure; | ||
import org.sonar.api.resources.Project; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* This class is used to save the measures created by the lizardReportParser in the sonar database | ||
* | ||
* @author Andres Gil Herrera | ||
* @since 28/05/15. | ||
*/ | ||
public class LizardMeasurePersistor { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(LizardMeasurePersistor.class); | ||
|
||
private final Project project; | ||
private final SensorContext sensorContext; | ||
private final FileSystem fileSystem; | ||
|
||
public LizardMeasurePersistor(final Project project, final SensorContext sensorContext, final FileSystem fileSystem) { | ||
this.project = project; | ||
this.sensorContext = sensorContext; | ||
this.fileSystem = fileSystem; | ||
} | ||
|
||
/** | ||
* | ||
* @param measures Map containing as key the name of the file and as value a list containing the measures for that file | ||
*/ | ||
public void saveMeasures(final Map<String, List<Measure>> measures) { | ||
|
||
if (measures == null) { | ||
return; | ||
} | ||
|
||
for (Map.Entry<String, List<Measure>> entry : measures.entrySet()) { | ||
final org.sonar.api.resources.File file = org.sonar.api.resources.File.fromIOFile(new File(fileSystem.baseDir(), entry.getKey()), project); | ||
|
||
if (sensorContext.getResource(file) != null) { | ||
for (Measure measure : entry.getValue()) { | ||
try { | ||
LOGGER.debug("Save measure {} for file {}", measure.getMetric().getName(), file); | ||
sensorContext.saveMeasure(file, measure); | ||
} catch (Exception e) { | ||
LOGGER.error(" Exception -> {} -> {}", entry.getKey(), measure.getMetric().getName(), e); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.