Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-6589 replace usage of ComputationContext.getRoot with TreeRootH…
…older also, ComponentTree is now computed as a step in BuildComponentTreeStep
- Loading branch information
Showing
22 changed files
with
599 additions
and
202 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
33 changes: 33 additions & 0 deletions
33
...ar-server/src/main/java/org/sonar/server/computation/component/MutableTreeRootHolder.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,33 @@ | ||
/* | ||
* 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 interface MutableTreeRootHolder extends TreeRootHolder { | ||
|
||
/** | ||
* Sets the root of the component tree in the TreeRootHolder. Settings a root more than once is allowed but it can | ||
* never be set to {@code null}. | ||
* | ||
* @param newRoot a {@link Component}, can not be {@code null} | ||
* | ||
* @throws NullPointerException if {@code newRoot} is {@code null} | ||
*/ | ||
void setRoot(Component newRoot); | ||
} |
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
42 changes: 42 additions & 0 deletions
42
...sonar-server/src/main/java/org/sonar/server/computation/component/TreeRootHolderImpl.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,42 @@ | ||
/* | ||
* 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; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Holds the reference to the root of the {@link Component} tree for the current CE run. | ||
*/ | ||
public class TreeRootHolderImpl implements MutableTreeRootHolder { | ||
private Component root; | ||
|
||
@Override | ||
public void setRoot(Component newRoot) { | ||
this.root = Objects.requireNonNull(newRoot); | ||
} | ||
|
||
@Override | ||
public Component getRoot() { | ||
if (this.root == null) { | ||
throw new IllegalStateException("Root has not been created yet"); | ||
} | ||
return this.root; | ||
} | ||
} |
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
72 changes: 72 additions & 0 deletions
72
.../sonar-server/src/main/java/org/sonar/server/computation/step/BuildComponentTreeStep.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,72 @@ | ||
/* | ||
* 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.base.Function; | ||
import com.google.common.collect.Iterables; | ||
import javax.annotation.Nonnull; | ||
import org.sonar.batch.protocol.output.BatchReport; | ||
import org.sonar.server.computation.ComputationContext; | ||
import org.sonar.server.computation.batch.BatchReportReader; | ||
import org.sonar.server.computation.component.Component; | ||
import org.sonar.server.computation.component.ComponentImpl; | ||
import org.sonar.server.computation.component.MutableTreeRootHolder; | ||
|
||
/** | ||
* Populates the {@link MutableTreeRootHolder} from the {@link BatchReportReader} | ||
*/ | ||
public class BuildComponentTreeStep implements ComputationStep { | ||
private final BatchReportReader reportReader; | ||
private final MutableTreeRootHolder mutableTreeRootHolder; | ||
|
||
public BuildComponentTreeStep(BatchReportReader reportReader, MutableTreeRootHolder mutableTreeRootHolder) { | ||
this.reportReader = reportReader; | ||
this.mutableTreeRootHolder = mutableTreeRootHolder; | ||
} | ||
|
||
@Override | ||
public void execute(ComputationContext context) { | ||
mutableTreeRootHolder.setRoot(buildComponentRoot()); | ||
} | ||
|
||
private Component buildComponentRoot() { | ||
int rootComponentRef = reportReader.readMetadata().getRootComponentRef(); | ||
BatchReport.Component component = reportReader.readComponent(rootComponentRef); | ||
return new ComponentImpl(component, buildChildren(component)); | ||
} | ||
|
||
private Iterable<Component> buildChildren(BatchReport.Component component) { | ||
return Iterables.transform( | ||
component.getChildRefList(), | ||
new Function<Integer, Component>() { | ||
@Override | ||
public Component apply(@Nonnull Integer componentRef) { | ||
BatchReport.Component component = reportReader.readComponent(componentRef); | ||
return new ComponentImpl(component, buildChildren(component)); | ||
} | ||
} | ||
); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Builds the Component tree"; | ||
} | ||
} |
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
Oops, something went wrong.