-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLM-19069 New index task to save a module descriptor for Nexus IQ. (#99)
- Loading branch information
1 parent
7046461
commit 26d7201
Showing
14 changed files
with
368 additions
and
26 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
98 changes: 98 additions & 0 deletions
98
src/main/java/org/sonatype/gradle/plugins/scan/nexus/iq/index/NexusIqIndexTask.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,98 @@ | ||
/* | ||
* Copyright (c) 2020-present Sonatype, Inc. | ||
* | ||
* Licensed 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.sonatype.gradle.plugins.scan.nexus.iq.index; | ||
|
||
import java.io.File; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import com.sonatype.insight.scan.module.model.Module; | ||
import com.sonatype.insight.scan.module.model.io.ModuleIoManager; | ||
|
||
import org.sonatype.gradle.plugins.scan.common.DependenciesFinder; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.GradleException; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.TaskAction; | ||
import org.gradle.internal.impldep.com.google.common.annotations.VisibleForTesting; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import static org.sonatype.gradle.plugins.scan.nexus.iq.scan.NexusIqPluginScanExtension.SONATYPE_CLM_FOLDER; | ||
|
||
public class NexusIqIndexTask | ||
extends DefaultTask | ||
{ | ||
public static final String MODULE_XML_FILE = "module.xml"; | ||
|
||
private final Logger log = LoggerFactory.getLogger(NexusIqIndexTask.class); | ||
|
||
private final NexusIqPluginIndexExtension extension; | ||
|
||
private DependenciesFinder dependenciesFinder; | ||
|
||
private ModuleIoManager moduleIoManager; | ||
|
||
public NexusIqIndexTask() { | ||
extension = getProject().getExtensions().getByType(NexusIqPluginIndexExtension.class); | ||
dependenciesFinder = new DependenciesFinder(); | ||
moduleIoManager = new ModuleIoManager(log); | ||
} | ||
|
||
@TaskAction | ||
public void saveModule() { | ||
try { | ||
List<Module> modules = | ||
dependenciesFinder.findModules(getProject(), extension.isAllConfigurations(), extension.getModulesExcluded()); | ||
List<File> files = new ArrayList<>(modules.size()); | ||
|
||
for (Module module : modules) { | ||
File file = Paths.get(module.getPathname(), "build", SONATYPE_CLM_FOLDER, MODULE_XML_FILE).toFile(); | ||
moduleIoManager.writeModule(file, module); | ||
files.add(file); | ||
} | ||
|
||
log.info("Saved module information to {}", StringUtils.join(files, ", ")); | ||
} | ||
catch (Exception e) { | ||
throw new GradleException("Could not save the module information for the project: " + e.getMessage(), e); | ||
} | ||
} | ||
|
||
@VisibleForTesting | ||
void setDependenciesFinder(DependenciesFinder dependenciesFinder) { | ||
this.dependenciesFinder = dependenciesFinder; | ||
} | ||
|
||
@VisibleForTesting | ||
void setModuleIoManager(ModuleIoManager moduleIoManager) { | ||
this.moduleIoManager = moduleIoManager; | ||
} | ||
|
||
@Input | ||
public boolean isAllConfigurations() { | ||
return extension.isAllConfigurations(); | ||
} | ||
|
||
@Input | ||
public Set<String> getModulesExcluded() { | ||
return extension.getModulesExcluded(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...ain/java/org/sonatype/gradle/plugins/scan/nexus/iq/index/NexusIqPluginIndexExtension.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,48 @@ | ||
/* | ||
* Copyright (c) 2020-present Sonatype, Inc. | ||
* | ||
* Licensed 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.sonatype.gradle.plugins.scan.nexus.iq.index; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
import org.gradle.api.Project; | ||
|
||
public class NexusIqPluginIndexExtension | ||
{ | ||
private boolean allConfigurations; | ||
|
||
private Set<String> modulesExcluded; | ||
|
||
public NexusIqPluginIndexExtension(Project project) { | ||
modulesExcluded = Collections.emptySet(); | ||
} | ||
|
||
public boolean isAllConfigurations() { | ||
return allConfigurations; | ||
} | ||
|
||
public void setAllConfigurations(boolean allConfigurations) { | ||
this.allConfigurations = allConfigurations; | ||
} | ||
|
||
public Set<String> getModulesExcluded() { | ||
return modulesExcluded; | ||
} | ||
|
||
public void setModulesExcluded(Set<String> modulesExcluded) { | ||
this.modulesExcluded = modulesExcluded; | ||
} | ||
} |
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.