this.children = children == null ? Collections.<Component>emptyList() : copyOf(filter(children, notNull()));
}
- private static Type convertType(Constants.ComponentType type) {
+ public static Type convertType(Constants.ComponentType type) {
switch (type) {
case PROJECT:
return Type.PROJECT;
+++ /dev/null
-/*
- * 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 ComponentTreeBuilder {
- /**
- * Builds the tree of components and returns the Component of the root of this tree.
- */
- Component build();
-}
+++ /dev/null
-/*
- * 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 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.batch.BatchReportReader;
-
-import static java.util.Objects.requireNonNull;
-
-public final class ComponentTreeBuilders {
- public static ComponentTreeBuilder from(final BatchReportReader reportReader) {
- // fail fast
- requireNonNull(reportReader);
-
- return new BatchReportComponentTreeBuilderImpl(reportReader);
- }
-
- public static ComponentTreeBuilder from(final Component root) {
- // fail-fast
- requireNonNull(root);
- return new ComponentTreeBuilder() {
- @Override
- public Component build() {
- return root;
- }
- };
- }
-
- public interface BatchReportComponentTreeBuilder extends ComponentTreeBuilder {
-
- }
-
- private static class BatchReportComponentTreeBuilderImpl implements BatchReportComponentTreeBuilder {
- private final BatchReportReader reportReader;
-
- public BatchReportComponentTreeBuilderImpl(BatchReportReader reportReader) {
- this.reportReader = reportReader;
- }
-
- @Override
- public Component build() {
- return buildComponentRoot(reportReader);
- }
-
- private Component buildComponentRoot(BatchReportReader reportReader) {
- int rootComponentRef = reportReader.readMetadata().getRootComponentRef();
- BatchReport.Component component = reportReader.readComponent(rootComponentRef);
- return new ComponentImpl(component, buildComponent(rootComponentRef));
- }
-
- private Iterable<Component> buildComponent(int componentRef) {
- BatchReport.Component component = reportReader.readComponent(componentRef);
- 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, buildComponent(componentRef));
- }
- }
- );
- }
- }
-}
--- /dev/null
+/*
+ * 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.Collections;
+import org.junit.Test;
+import org.sonar.batch.protocol.Constants;
+import org.sonar.batch.protocol.output.BatchReport;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ComponentImplTest {
+ private ComponentImpl component = new ComponentImpl(BatchReport.Component.newBuilder().build(), Collections.<Component>emptyList());
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getUuid_throws_UOE_if_uuid_has_not_been_set_yet() {
+ component.getUuid();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getKey_throws_UOE_if_uuid_has_not_been_set_yet() {
+ component.getKey();
+ }
+
+ @Test
+ public void verify_setUuid() {
+ String uuid = "toto";
+ assertThat(component.setUuid(uuid).getUuid()).isEqualTo(uuid);
+ }
+
+ @Test
+ public void verify_setKey() {
+ String key = "toto";
+ assertThat(component.setKey(key).getKey()).isEqualTo(key);
+ }
+
+ @Test
+ public void convertType() {
+ for (Constants.ComponentType componentType : Constants.ComponentType.values()) {
+ assertThat(ComponentImpl.convertType(componentType)).isEqualTo(Component.Type.valueOf(componentType.name()));
+ }
+ }
+}
--- /dev/null
+/*
+ * 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 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.batch.BatchReportReader;
+
+public final class ComponentTreeBuilder {
+ public static Component from(final BatchReportReader reportReader) {
+ return buildComponentRoot(reportReader);
+ }
+
+ private static Component buildComponentRoot(BatchReportReader reportReader) {
+ int rootComponentRef = reportReader.readMetadata().getRootComponentRef();
+ BatchReport.Component component = reportReader.readComponent(rootComponentRef);
+ return newComponent(reportReader, component);
+ }
+
+ private static Iterable<Component> buildChildren(final BatchReportReader reportReader, final 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 newComponent(reportReader, component);
+ }
+ }
+ );
+ }
+
+ private static Component newComponent(BatchReportReader reportReader, BatchReport.Component component) {
+ return new ComponentImpl(component, buildChildren(reportReader, component));
+ }
+}
import org.sonar.server.computation.batch.BatchReportReaderRule;
import org.sonar.server.computation.batch.TreeRootHolderRule;
import org.sonar.server.computation.component.Component;
-import org.sonar.server.computation.component.ComponentTreeBuilders;
+import org.sonar.server.computation.component.ComponentTreeBuilder;
import org.sonar.server.db.DbClient;
import org.sonar.test.DbTests;
.setPath("src/main/java/dir/Foo.java")
.build());
- treeRootHolder.setRoot(ComponentTreeBuilders.from(reportReader).build());
+ treeRootHolder.setRoot(ComponentTreeBuilder.from(reportReader));
sut.execute();
Map<Integer, Component> componentsByRef = getComponentsByRef(treeRootHolder.getRoot());
.setPath("src/main/java/dir/Foo.java")
.build());
- treeRootHolder.setRoot(ComponentTreeBuilders.from(reportReader).build());
+ treeRootHolder.setRoot(ComponentTreeBuilder.from(reportReader));
sut.execute();
Map<Integer, Component> componentsByRef = getComponentsByRef(treeRootHolder.getRoot());
.setPath("src/main/java/dir/Foo.java")
.build());
- treeRootHolder.setRoot(ComponentTreeBuilders.from(reportReader).build());
+ treeRootHolder.setRoot(ComponentTreeBuilder.from(reportReader));
sut.execute();
Map<Integer, Component> componentsByRef = getComponentsByRef(treeRootHolder.getRoot());