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
1 parent
303f3f2
commit a27d5ef
Showing
15 changed files
with
1,279 additions
and
138 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
55 changes: 55 additions & 0 deletions
55
server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,55 @@ | |||
/* | |||
* 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.server.computation.component; | |||
|
|||
public class Component { | |||
|
|||
private Long id; | |||
private String uuid; | |||
private String key; | |||
|
|||
public Long getId() { | |||
return id; | |||
} | |||
|
|||
public Component setId(Long id) { | |||
this.id = id; | |||
return this; | |||
} | |||
|
|||
public String getKey() { | |||
return key; | |||
} | |||
|
|||
public Component setKey(String key) { | |||
this.key = key; | |||
return this; | |||
} | |||
|
|||
public String getUuid() { | |||
return uuid; | |||
} | |||
|
|||
public Component setUuid(String uuid) { | |||
this.uuid = uuid; | |||
return this; | |||
} | |||
} |
44 changes: 44 additions & 0 deletions
44
server/sonar-server/src/main/java/org/sonar/server/computation/step/ComponentsCache.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,44 @@ | |||
/* | |||
* 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.server.computation.step; | |||
|
|||
import org.sonar.batch.protocol.output.BatchReportReader; | |||
import org.sonar.server.computation.component.Component; | |||
|
|||
import java.util.HashMap; | |||
import java.util.Map; | |||
|
|||
/** | |||
* To be finished | |||
*/ | |||
public class ComponentsCache { | |||
|
|||
private final Map<Integer, Component> componentsByRef; | |||
|
|||
public ComponentsCache(final BatchReportReader reader) { | |||
this.componentsByRef = new HashMap<>(); | |||
} | |||
|
|||
public Component getComponent(int componentRef) { | |||
// TODO should we return null or fail on unknown component ? | |||
return null; | |||
} | |||
} |
107 changes: 107 additions & 0 deletions
107
...sonar-server/src/main/java/org/sonar/server/computation/step/FeedComponentsCacheStep.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,107 @@ | |||
/* | |||
* 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.server.computation.step; | |||
|
|||
import com.google.common.collect.Maps; | |||
import org.sonar.api.resources.Qualifiers; | |||
import org.sonar.api.utils.internal.Uuids; | |||
import org.sonar.batch.protocol.Constants; | |||
import org.sonar.batch.protocol.output.BatchReport; | |||
import org.sonar.batch.protocol.output.BatchReportReader; | |||
import org.sonar.core.component.ComponentDto; | |||
import org.sonar.core.component.ComponentKeys; | |||
import org.sonar.core.persistence.DbSession; | |||
import org.sonar.core.util.NonNullInputFunction; | |||
import org.sonar.server.computation.ComputationContext; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.db.DbClient; | |||
|
|||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
|
|||
/** | |||
* To be finished | |||
*/ | |||
public class FeedComponentsCacheStep implements ComputationStep { | |||
|
|||
private final DbClient dbClient; | |||
|
|||
public FeedComponentsCacheStep(DbClient dbClient) { | |||
this.dbClient = dbClient; | |||
} | |||
|
|||
@Override | |||
public String[] supportedProjectQualifiers() { | |||
return new String[] {Qualifiers.PROJECT}; | |||
} | |||
|
|||
@Override | |||
public void execute(ComputationContext context) { | |||
DbSession session = dbClient.openSession(false); | |||
try { | |||
List<ComponentDto> components = dbClient.componentDao().selectComponentsFromProjectUuid(session, context.getProject().uuid()); | |||
Map<String, ComponentDto> componentDtosByKey = componentDtosByKey(components); | |||
Map<Integer, Component> componentsByRef = new HashMap<>(); | |||
int rootComponentRef = context.getReportMetadata().getRootComponentRef(); | |||
recursivelyProcessComponent(context, rootComponentRef, context.getReportReader().readComponent(rootComponentRef), componentDtosByKey, componentsByRef); | |||
} finally { | |||
session.close(); | |||
} | |||
} | |||
|
|||
private void recursivelyProcessComponent(ComputationContext context, int componentRef, BatchReport.Component nearestModule, | |||
Map<String, ComponentDto> componentDtosByKey, Map<Integer, Component> componentsByRef) { | |||
BatchReportReader reportReader = context.getReportReader(); | |||
BatchReport.Component reportComponent = reportReader.readComponent(componentRef); | |||
String componentKey = ComponentKeys.createKey(nearestModule.getKey(), reportComponent.getPath(), context.getReportMetadata().getBranch()); | |||
|
|||
Component component = new Component().setKey(componentKey); | |||
ComponentDto componentDto = componentDtosByKey.get(componentKey); | |||
if (componentDto == null) { | |||
component.setUuid(Uuids.create()); | |||
} else { | |||
component.setId(component.getId()); | |||
component.setKey(componentKey); | |||
} | |||
|
|||
for (Integer childRef : reportComponent.getChildRefList()) { | |||
// If current component is not a module or a project, we need to keep the parent reference to the nearest module | |||
BatchReport.Component nextNearestModule = !reportComponent.getType().equals(Constants.ComponentType.PROJECT) && !reportComponent.getType().equals(Constants.ComponentType.MODULE) ? | |||
nearestModule : reportComponent; | |||
recursivelyProcessComponent(context, childRef, nextNearestModule, componentDtosByKey, componentsByRef); | |||
} | |||
} | |||
|
|||
private Map<String, ComponentDto> componentDtosByKey(List<ComponentDto> components){ | |||
return Maps.uniqueIndex(components, new NonNullInputFunction<ComponentDto, String>() { | |||
@Override | |||
public String doApply(ComponentDto input) { | |||
return input.key(); | |||
} | |||
}); | |||
} | |||
|
|||
@Override | |||
public String getDescription() { | |||
return "Feed components cache"; | |||
} | |||
} |
Oops, something went wrong.