This is an automated email from the ASF dual-hosted git repository. sseifert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-launchpad-comparator.git
commit 0087336a20efabd5dd79d64bdd90c2e8935c5091 Author: Stefan Seifert <[email protected]> AuthorDate: Mon Dec 16 13:33:43 2024 +0100 apply spotless formatting --- pom.xml | 30 +++-- .../apache/sling/tooling/lc/LaunchpadComparer.java | 134 +++++++++++---------- .../java/org/apache/sling/tooling/lc/Main.java | 36 +++--- .../sling/tooling/lc/aether/AetherSetup.java | 51 ++++---- .../sling/tooling/lc/aether/ArtifactKey.java | 69 ++++++----- .../apache/sling/tooling/lc/aether/Artifacts.java | 46 +++---- .../sling/tooling/lc/aether/VersionChange.java | 42 ++++--- .../sling/tooling/lc/git/GitChangeLogFinder.java | 70 ++++++----- .../org/apache/sling/tooling/lc/jira/Fields.java | 35 +++--- .../org/apache/sling/tooling/lc/jira/Issue.java | 58 ++++----- .../apache/sling/tooling/lc/jira/IssueFinder.java | 69 ++++++----- .../org/apache/sling/tooling/lc/jira/Response.java | 30 ++--- .../org/apache/sling/tooling/lc/ArtifactsTest.java | 60 ++++----- 13 files changed, 377 insertions(+), 353 deletions(-) diff --git a/pom.xml b/pom.xml index 991983e..a929a11 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,4 @@ -<?xml version="1.0"?> +<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to @@ -9,14 +9,13 @@ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.apache.sling</groupId> <artifactId>sling</artifactId> <version>62</version> - <relativePath/> + <relativePath /> </parent> <groupId>org.apache.sling.tooling</groupId> <artifactId>launchpad-comparator</artifactId> @@ -24,6 +23,13 @@ <name>Apache Sling Launchpad Comparator</name> <description>Command line utility which helps with comparing the artifacts contained by two launchpad instances.</description> + <properties> + <sling.java.version>8</sling.java.version> + <aetherVersion>1.0.0.v20140518</aetherVersion> + <mavenVersion>3.1.0</mavenVersion> + <wagonVersion>1.0</wagonVersion> + </properties> + <dependencies> <!-- Aether dependencies start --> @@ -118,7 +124,7 @@ <version>2.2.4</version> <scope>compile</scope> </dependency> - + <!-- Testing --> <dependency> <groupId>junit</groupId> @@ -136,8 +142,7 @@ <version>2.4.1</version> <configuration> <transformers> - <transformer - implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> + <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>org.apache.sling.tooling.lc.Main</mainClass> </transformer> </transformers> @@ -155,10 +160,10 @@ </configuration> <executions> <execution> - <phase>package</phase> <goals> <goal>shade</goal> </goals> + <phase>package</phase> </execution> </executions> </plugin> @@ -173,11 +178,4 @@ </plugin> </plugins> </build> - - <properties> - <sling.java.version>8</sling.java.version> - <aetherVersion>1.0.0.v20140518</aetherVersion> - <mavenVersion>3.1.0</mavenVersion> - <wagonVersion>1.0</wagonVersion> - </properties> -</project> \ No newline at end of file +</project> diff --git a/src/main/java/org/apache/sling/tooling/lc/LaunchpadComparer.java b/src/main/java/org/apache/sling/tooling/lc/LaunchpadComparer.java index 6392e74..01df6bd 100644 --- a/src/main/java/org/apache/sling/tooling/lc/LaunchpadComparer.java +++ b/src/main/java/org/apache/sling/tooling/lc/LaunchpadComparer.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.tooling.lc; @@ -30,6 +32,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.StreamSupport; +import com.google.common.collect.Sets; import org.apache.sling.provisioning.model.Artifact; import org.apache.sling.provisioning.model.Model; import org.apache.sling.provisioning.model.ModelUtility; @@ -42,10 +45,8 @@ import org.apache.sling.tooling.lc.git.GitChangeLogFinder; import org.apache.sling.tooling.lc.jira.IssueFinder; import org.eclipse.jgit.api.errors.GitAPIException; -import com.google.common.collect.Sets; - public class LaunchpadComparer { - + private static final Pattern JIRA_KEY_PATTERN = Pattern.compile("^(SLING-\\d+).*"); private final String firstVersion; @@ -59,10 +60,10 @@ public class LaunchpadComparer { } public void run() throws Exception { - - System.out.format("Computing differences between Launchpad versions %s and %s...%n", - firstVersion, secondVersion); - + + System.out.format( + "Computing differences between Launchpad versions %s and %s...%n", firstVersion, secondVersion); + // 1. download artifacts AetherSetup aether = new AetherSetup(); @@ -72,36 +73,37 @@ public class LaunchpadComparer { // 2. parse artifact definitions Map<ArtifactKey, Artifact> from = readArtifactsFromModel(fromFile); Map<ArtifactKey, Artifact> to = readArtifactsFromModel(toFile); - - + // 3. generate added / removed / changed Set<Artifact> removed = Sets.difference(from.keySet(), to.keySet()).stream() - .map( k -> from.get(k)) - .collect(Collectors.toSet()); + .map(k -> from.get(k)) + .collect(Collectors.toSet()); Set<Artifact> added = Sets.difference(to.keySet(), from.keySet()).stream() - .map( k -> to.get(k)) + .map(k -> to.get(k)) .collect(Collectors.toSet()); Map<ArtifactKey, VersionChange> changed = to.values().stream() - .filter( k -> !added.contains(k) && !removed.contains(k)) - .map( k -> new ArtifactKey(k)) - .filter( k -> !Objects.equals(to.get(k).getVersion(), from.get(k).getVersion())) - .collect(Collectors.toMap( Function.identity(), k -> new VersionChange(from.get(k).getVersion(), to.get(k).getVersion()))); + .filter(k -> !added.contains(k) && !removed.contains(k)) + .map(k -> new ArtifactKey(k)) + .filter(k -> !Objects.equals(to.get(k).getVersion(), from.get(k).getVersion())) + .collect(Collectors.toMap( + Function.identity(), + k -> new VersionChange( + from.get(k).getVersion(), to.get(k).getVersion()))); // 4. output changes - + System.out.println("Added "); added.stream().sorted().forEach(LaunchpadComparer::outputFormatted); - + System.out.println("Removed "); removed.stream().sorted().forEach(LaunchpadComparer::outputFormatted); - + System.out.println("Changed"); changed.entrySet().stream() - .sorted( (a, b) -> a.getKey().compareTo(b.getKey()) ) - .forEach(this::outputFormatted); - + .sorted((a, b) -> a.getKey().compareTo(b.getKey())) + .forEach(this::outputFormatted); } private Map<ArtifactKey, Artifact> readArtifactsFromModel(File toFile) throws IOException { @@ -109,57 +111,59 @@ public class LaunchpadComparer { try (BufferedReader reader = Files.newBufferedReader(toFile.toPath())) { fromModel = ModelUtility.getEffectiveModel(ModelReader.read(reader, null)); } - + Map<ArtifactKey, Artifact> to = fromModel.getFeatures().stream() - .flatMap( f -> f.getRunModes().stream()) - .flatMap( r -> r.getArtifactGroups().stream()) - .flatMap( g -> StreamSupport.stream(g.spliterator(), false)) - .collect(Collectors.toMap( a -> new ArtifactKey(a), Function.identity())); + .flatMap(f -> f.getRunModes().stream()) + .flatMap(r -> r.getArtifactGroups().stream()) + .flatMap(g -> StreamSupport.stream(g.spliterator(), false)) + .collect(Collectors.toMap(a -> new ArtifactKey(a), Function.identity())); return to; } - + private static void outputFormatted(Artifact a) { - + System.out.format(" %-30s : %-55s : %s%n", a.getGroupId(), a.getArtifactId(), a.getVersion()); - } private void outputFormatted(Map.Entry<ArtifactKey, VersionChange> e) { - + ArtifactKey artifact = e.getKey(); VersionChange versionChange = e.getValue(); - - System.out.format(" %-30s : %-55s : %s -> %s%n", artifact.getGroupId(), artifact.getArtifactId(), versionChange.getFrom(), versionChange.getTo()); - - if ( !artifact.getGroupId().equals("org.apache.sling")) { + + System.out.format( + " %-30s : %-55s : %s -> %s%n", + artifact.getGroupId(), artifact.getArtifactId(), versionChange.getFrom(), versionChange.getTo()); + + if (!artifact.getGroupId().equals("org.apache.sling")) { return; } - + GitChangeLogFinder git = new GitChangeLogFinder(slingRepoCheckout); - + try { - List<String> issues = git.getChanges(artifact.getArtifactId(), versionChange.getFrom(), versionChange.getTo()) - .stream() - .map( m -> m.split(System.lineSeparator())[0]) - .map(LaunchpadComparer::toJiraKey) - .filter( k -> k != null) - .collect(Collectors.toList()); - + List<String> issues = + git.getChanges(artifact.getArtifactId(), versionChange.getFrom(), versionChange.getTo()).stream() + .map(m -> m.split(System.lineSeparator())[0]) + .map(LaunchpadComparer::toJiraKey) + .filter(k -> k != null) + .collect(Collectors.toList()); + IssueFinder issueFinder = new IssueFinder(); - issueFinder.findIssues(issues). - forEach( i -> System.out.format(" %-10s - %s%n", i.getKey(), i.getSummary())); - + issueFinder + .findIssues(issues) + .forEach(i -> System.out.format(" %-10s - %s%n", i.getKey(), i.getSummary())); + } catch (GitAPIException | IOException e1) { System.err.println("Failed retrieving changes : " + e1.getMessage()); } } - + private static String toJiraKey(String message) { Matcher matcher = JIRA_KEY_PATTERN.matcher(message); - if ( !matcher.matches() ) { + if (!matcher.matches()) { return null; } - + return matcher.group(1); - } + } } diff --git a/src/main/java/org/apache/sling/tooling/lc/Main.java b/src/main/java/org/apache/sling/tooling/lc/Main.java index 46e8d63..0e4be41 100644 --- a/src/main/java/org/apache/sling/tooling/lc/Main.java +++ b/src/main/java/org/apache/sling/tooling/lc/Main.java @@ -1,32 +1,34 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.tooling.lc; public class Main { public static void main(String[] args) throws Exception { - + String firstVersion = "8"; String secondVersion = "9"; - if ( args.length == 2) { + if (args.length == 2) { firstVersion = args[0]; secondVersion = args[1]; } - + new LaunchpadComparer(firstVersion, secondVersion, "..").run(); } } diff --git a/src/main/java/org/apache/sling/tooling/lc/aether/AetherSetup.java b/src/main/java/org/apache/sling/tooling/lc/aether/AetherSetup.java index 8d4679b..5f0cf9c 100644 --- a/src/main/java/org/apache/sling/tooling/lc/aether/AetherSetup.java +++ b/src/main/java/org/apache/sling/tooling/lc/aether/AetherSetup.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.tooling.lc.aether; @@ -37,34 +39,33 @@ import org.eclipse.aether.transport.file.FileTransporterFactory; import org.eclipse.aether.transport.http.HttpTransporterFactory; public class AetherSetup { - + private final List<RemoteRepository> repos = Arrays.asList( - new RemoteRepository.Builder("central", "default", "http://central.maven.org/maven2/").build(), - new RemoteRepository.Builder("apache", "default", "https://repository.apache.org/content/groups/snapshots/").build() - ); - + new RemoteRepository.Builder("central", "default", "http://central.maven.org/maven2/").build(), + new RemoteRepository.Builder("apache", "default", "https://repository.apache.org/content/groups/snapshots/") + .build()); + private final RepositorySystem system; private final DefaultRepositorySystemSession session; - - + public AetherSetup() { - + DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator(); locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class); locator.addService(TransporterFactory.class, FileTransporterFactory.class); locator.addService(TransporterFactory.class, HttpTransporterFactory.class); system = locator.getService(RepositorySystem.class); - + session = MavenRepositorySystemUtils.newSession(); LocalRepository localRepo = new LocalRepository("target/local-repo"); session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo)); } - public File download(String coordinates) throws ArtifactResolutionException { - ArtifactResult fromResult = system.resolveArtifact(session, new ArtifactRequest(new DefaultArtifact(coordinates), repos, null)); + ArtifactResult fromResult = + system.resolveArtifact(session, new ArtifactRequest(new DefaultArtifact(coordinates), repos, null)); return fromResult.getArtifact().getFile(); } diff --git a/src/main/java/org/apache/sling/tooling/lc/aether/ArtifactKey.java b/src/main/java/org/apache/sling/tooling/lc/aether/ArtifactKey.java index 3f81a6f..a4aaa37 100644 --- a/src/main/java/org/apache/sling/tooling/lc/aether/ArtifactKey.java +++ b/src/main/java/org/apache/sling/tooling/lc/aether/ArtifactKey.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.tooling.lc.aether; @@ -21,17 +23,17 @@ import java.util.Objects; import org.apache.sling.provisioning.model.Artifact; public class ArtifactKey implements Comparable<ArtifactKey> { - + private String groupId; private String artifactId; private String classifier; private String type; - + public ArtifactKey(Artifact artifact) { - + this(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getType()); } - + private ArtifactKey(String groupId, String artifactId, String classifier, String type) { this.groupId = groupId; this.artifactId = artifactId; @@ -41,53 +43,54 @@ public class ArtifactKey implements Comparable<ArtifactKey> { @Override public int hashCode() { - + return Objects.hash(artifactId, classifier, groupId, type); } @Override public boolean equals(Object obj) { - - if ( !(obj instanceof ArtifactKey) ) { + + if (!(obj instanceof ArtifactKey)) { return false; } - + ArtifactKey other = (ArtifactKey) obj; - + return Objects.equals(artifactId, other.artifactId) && Objects.equals(groupId, other.groupId) && Objects.equals(classifier, other.classifier) && Objects.equals(type, other.type); } - + public String getArtifactId() { return artifactId; } - + public String getGroupId() { return groupId; } - + public String getClassifier() { return classifier; } - + public String getType() { return type; } - + @Override public String toString() { - - return "Artifact [groupId=" + groupId + ", artifactId=" + artifactId + ", classifier=" + classifier + ", type=" + type + "]"; + + return "Artifact [groupId=" + groupId + ", artifactId=" + artifactId + ", classifier=" + classifier + ", type=" + + type + "]"; } @Override public int compareTo(ArtifactKey o) { - + Artifact us = new Artifact(groupId, artifactId, "0.0.0", classifier, type); Artifact them = new Artifact(o.groupId, o.artifactId, "0.0.0", o.classifier, o.type); - + return us.compareTo(them); } -} \ No newline at end of file +} diff --git a/src/main/java/org/apache/sling/tooling/lc/aether/Artifacts.java b/src/main/java/org/apache/sling/tooling/lc/aether/Artifacts.java index 6e7c625..a9c3273 100644 --- a/src/main/java/org/apache/sling/tooling/lc/aether/Artifacts.java +++ b/src/main/java/org/apache/sling/tooling/lc/aether/Artifacts.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.tooling.lc.aether; @@ -22,23 +24,23 @@ import java.util.regex.Pattern; public class Artifacts { private static final Pattern VERSION_NUMBER = Pattern.compile("^(\\d+)(-SNAPSHOT)?"); - + public static final String launchpadCoordinates(String version) { - + Matcher versionMatcher = VERSION_NUMBER.matcher(version); - - if ( !versionMatcher.matches()) { + + if (!versionMatcher.matches()) { throw new IllegalArgumentException("Invalid version " + version); } - + int versionNumber = Integer.parseInt(versionMatcher.group(1)); // versions 6 and 7 used an XML bundle list - if ( versionNumber < 8 ) { + if (versionNumber < 8) { return "org.apache.sling:org.apache.sling.launchpad:xml:bundlelist:" + version; } - - String artifactId = versionNumber < 10 ? "org.apache.sling.launchpad" : "org.apache.sling.starter"; + + String artifactId = versionNumber < 10 ? "org.apache.sling.launchpad" : "org.apache.sling.starter"; // versions 8 and newer use the provisioning model return "org.apache.sling:" + artifactId + ":txt:slingfeature:" + version; } diff --git a/src/main/java/org/apache/sling/tooling/lc/aether/VersionChange.java b/src/main/java/org/apache/sling/tooling/lc/aether/VersionChange.java index 671ff2e..764278c 100644 --- a/src/main/java/org/apache/sling/tooling/lc/aether/VersionChange.java +++ b/src/main/java/org/apache/sling/tooling/lc/aether/VersionChange.java @@ -1,23 +1,25 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.tooling.lc.aether; public class VersionChange { - + private String from; private String to; @@ -25,17 +27,17 @@ public class VersionChange { this.from = from; this.to = to; } - + public String getFrom() { return from; } - + public String getTo() { return to; } - + @Override public String toString() { - return "VersionChange [" +from + " -> " + to +"]"; + return "VersionChange [" + from + " -> " + to + "]"; } -} \ No newline at end of file +} diff --git a/src/main/java/org/apache/sling/tooling/lc/git/GitChangeLogFinder.java b/src/main/java/org/apache/sling/tooling/lc/git/GitChangeLogFinder.java index c4df594..933a084 100644 --- a/src/main/java/org/apache/sling/tooling/lc/git/GitChangeLogFinder.java +++ b/src/main/java/org/apache/sling/tooling/lc/git/GitChangeLogFinder.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.tooling.lc.git; @@ -30,14 +32,15 @@ import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.storage.file.FileRepositoryBuilder; public class GitChangeLogFinder { - - public static void main(String[] args) throws IOException, GitAPIException { - new GitChangeLogFinder("..").getChanges("org.apache.sling.adapter", "2.1.2", "2.1.6") - .stream().forEach(System.out::println); + + public static void main(String[] args) throws IOException, GitAPIException { + new GitChangeLogFinder("..") + .getChanges("org.apache.sling.adapter", "2.1.2", "2.1.6").stream() + .forEach(System.out::println); } - + private final String slingRepoCheckoutDir; - + /** * @param slingRepoCheckoutDir the <tt>repo</tt> root for Apache Sling */ @@ -46,12 +49,13 @@ public class GitChangeLogFinder { } public List<String> getChanges(String artifactId, String from, String to) throws IOException, GitAPIException { - + Path repoPath = Paths.get(slingRepoCheckoutDir, artifactId.replace('.', '-'), ".git"); - + FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder(); - - Repository repository = repositoryBuilder.setGitDir(repoPath.toFile()) + + Repository repository = repositoryBuilder + .setGitDir(repoPath.toFile()) .readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .setMustExist(true) @@ -59,26 +63,26 @@ public class GitChangeLogFinder { Ref fromTag = getTagChecked(repository, artifactId, from); Ref toTag = getTagChecked(repository, artifactId, to); - + Git git = Git.wrap(repository); - + fromTag = repository.getRefDatabase().peel(fromTag); toTag = repository.getRefDatabase().peel(toTag); - + List<String> commits = new ArrayList<>(); git.log() - .addRange(fromTag.getPeeledObjectId(), toTag.getPeeledObjectId()) - .call() - .forEach( c -> commits.add(c.getShortMessage())); - + .addRange(fromTag.getPeeledObjectId(), toTag.getPeeledObjectId()) + .call() + .forEach(c -> commits.add(c.getShortMessage())); + return commits; } private Ref getTagChecked(Repository repository, String artifactId, String version) throws IOException { - + final String tagName = artifactId + "-" + version; final Ref ref = repository.getRefDatabase().getRef(Constants.R_TAGS + tagName); - if ( ref == null ) + if (ref == null) throw new RuntimeException("No tag " + tagName + " found in git repo at " + repository.getDirectory()); return ref; } diff --git a/src/main/java/org/apache/sling/tooling/lc/jira/Fields.java b/src/main/java/org/apache/sling/tooling/lc/jira/Fields.java index 2215d06..66e8d62 100644 --- a/src/main/java/org/apache/sling/tooling/lc/jira/Fields.java +++ b/src/main/java/org/apache/sling/tooling/lc/jira/Fields.java @@ -1,25 +1,27 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.tooling.lc.jira; public class Fields { - + private final String summary; - + public Fields(String summary) { this.summary = summary; } @@ -27,5 +29,4 @@ public class Fields { public String getSummary() { return summary; } - } diff --git a/src/main/java/org/apache/sling/tooling/lc/jira/Issue.java b/src/main/java/org/apache/sling/tooling/lc/jira/Issue.java index 150a5e5..2878b50 100644 --- a/src/main/java/org/apache/sling/tooling/lc/jira/Issue.java +++ b/src/main/java/org/apache/sling/tooling/lc/jira/Issue.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.tooling.lc.jira; @@ -20,10 +22,9 @@ import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; - public class Issue implements Comparable<Issue> { - - private static final Pattern KEY_PATTERN = Pattern.compile("^([A-Z]+)-(\\d+)$"); + + private static final Pattern KEY_PATTERN = Pattern.compile("^([A-Z]+)-(\\d+)$"); private final String key; private final Fields fields; @@ -36,15 +37,15 @@ public class Issue implements Comparable<Issue> { public String getKey() { return key; } - + public Fields getFields() { return fields; } - + public String getSummary() { return fields.getSummary(); } - + @Override public String toString() { return key + " - " + getSummary(); @@ -52,26 +53,25 @@ public class Issue implements Comparable<Issue> { @Override public int compareTo(Issue o) { - + Matcher ourMatcher = KEY_PATTERN.matcher(key); Matcher theirMatcher = KEY_PATTERN.matcher(o.key); - - if ( !ourMatcher.matches()) { + + if (!ourMatcher.matches()) { throw new IllegalArgumentException("No match found for " + key); } - if ( !theirMatcher.matches()) { + if (!theirMatcher.matches()) { throw new IllegalArgumentException("No match found for " + o.key); } - + String ourProject = ourMatcher.group(1); String theirProject = theirMatcher.group(1); - - - if ( !Objects.equals(ourProject, theirProject)) { + + if (!Objects.equals(ourProject, theirProject)) { return ourProject.compareTo(theirProject); } - + int ourId = Integer.parseInt(ourMatcher.group(2)); int theirId = Integer.parseInt(theirMatcher.group(2)); diff --git a/src/main/java/org/apache/sling/tooling/lc/jira/IssueFinder.java b/src/main/java/org/apache/sling/tooling/lc/jira/IssueFinder.java index d7bcedd..68f5db9 100644 --- a/src/main/java/org/apache/sling/tooling/lc/jira/IssueFinder.java +++ b/src/main/java/org/apache/sling/tooling/lc/jira/IssueFinder.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.tooling.lc.jira; @@ -24,6 +26,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import com.google.gson.Gson; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; @@ -31,53 +34,49 @@ import org.apache.http.client.utils.HttpClientUtils; import org.apache.http.client.utils.URIBuilder; import org.apache.http.impl.client.DefaultHttpClient; -import com.google.gson.Gson; - public class IssueFinder { - + public static void main(String[] args) throws IOException { - - new IssueFinder().findIssues(Arrays.asList("SLING-1", "SLING-2")) - .stream() - .forEach(System.out::println); + + new IssueFinder() + .findIssues(Arrays.asList("SLING-1", "SLING-2")).stream().forEach(System.out::println); } - - public List<Issue> findIssues(List<String> issueKeys) throws IOException{ - - if ( issueKeys.isEmpty() ) { + + public List<Issue> findIssues(List<String> issueKeys) throws IOException { + + if (issueKeys.isEmpty()) { return Collections.emptyList(); } - + HttpClient client = new DefaultHttpClient(); - + HttpGet get; try { URIBuilder builder = new URIBuilder("https://issues.apache.org/jira/rest/api/2/search") .addParameter("jql", "key in (" + String.join(",", issueKeys) + ")") .addParameter("fields", "key,summary"); - + get = new HttpGet(builder.build()); } catch (URISyntaxException e) { // never happens throw new RuntimeException(e); } - + HttpResponse response = client.execute(get); try { - if ( response.getStatusLine().getStatusCode() != 200 ) { - throw new IOException("Search call returned status " + response.getStatusLine().getStatusCode()); + if (response.getStatusLine().getStatusCode() != 200) { + throw new IOException("Search call returned status " + + response.getStatusLine().getStatusCode()); } - - try ( Reader reader = new InputStreamReader(response.getEntity().getContent(), "UTF-8") ) { + + try (Reader reader = new InputStreamReader(response.getEntity().getContent(), "UTF-8")) { Response apiResponse = new Gson().fromJson(reader, Response.class); List<Issue> issues = apiResponse.getIssues(); Collections.sort(issues); return issues; - } } finally { HttpClientUtils.closeQuietly(client); } - } } diff --git a/src/main/java/org/apache/sling/tooling/lc/jira/Response.java b/src/main/java/org/apache/sling/tooling/lc/jira/Response.java index e77407f..75b70eb 100644 --- a/src/main/java/org/apache/sling/tooling/lc/jira/Response.java +++ b/src/main/java/org/apache/sling/tooling/lc/jira/Response.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.tooling.lc.jira; diff --git a/src/test/java/org/apache/sling/tooling/lc/ArtifactsTest.java b/src/test/java/org/apache/sling/tooling/lc/ArtifactsTest.java index 8b3b396..0a82dbb 100644 --- a/src/test/java/org/apache/sling/tooling/lc/ArtifactsTest.java +++ b/src/test/java/org/apache/sling/tooling/lc/ArtifactsTest.java @@ -1,51 +1,57 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.tooling.lc; +import org.junit.Test; + import static org.apache.sling.tooling.lc.aether.Artifacts.launchpadCoordinates; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; -import org.junit.Test; - public class ArtifactsTest { - + @Test public void launchpadV7() { - + assertThat(launchpadCoordinates("7"), equalTo("org.apache.sling:org.apache.sling.launchpad:xml:bundlelist:7")); } - + @Test public void launchpadV7Snapshot() { - - assertThat(launchpadCoordinates("7-SNAPSHOT"), equalTo("org.apache.sling:org.apache.sling.launchpad:xml:bundlelist:7-SNAPSHOT")); + + assertThat( + launchpadCoordinates("7-SNAPSHOT"), + equalTo("org.apache.sling:org.apache.sling.launchpad:xml:bundlelist:7-SNAPSHOT")); } @Test public void launchpadV8() { - - assertThat(launchpadCoordinates("8"), equalTo("org.apache.sling:org.apache.sling.launchpad:txt:slingfeature:8")); + + assertThat( + launchpadCoordinates("8"), equalTo("org.apache.sling:org.apache.sling.launchpad:txt:slingfeature:8")); } - + @Test public void launchpadV8Snapshot() { - - assertThat(launchpadCoordinates("8-SNAPSHOT"), equalTo("org.apache.sling:org.apache.sling.launchpad:txt:slingfeature:8-SNAPSHOT")); - } + assertThat( + launchpadCoordinates("8-SNAPSHOT"), + equalTo("org.apache.sling:org.apache.sling.launchpad:txt:slingfeature:8-SNAPSHOT")); + } }
