-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply rules to implicitly created directories
- Loading branch information
Showing
5 changed files
with
226 additions
and
2 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/main/java/de/dentrassi/rpm/builder/BuilderContextListener.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,22 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Fraunhofer-Institut fuer Optronik, Systemtechnik und Bildauswertung IOSB and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* Contributors: | ||
* Fraunhofer-Institut fuer Optronik, Systemtechnik und Bildauswertung IOSB - initial API and implementation | ||
*******************************************************************************/ | ||
package de.dentrassi.rpm.builder; | ||
|
||
import org.eclipse.packager.rpm.build.FileInformationProvider; | ||
|
||
public interface BuilderContextListener { | ||
|
||
void notifyFileAdded(String name, FileInformationProvider<Object> provider); | ||
|
||
void notifyDirectoryAdded(String name, FileInformationProvider<Object> provider); | ||
|
||
void notifySymbolicLinkAdded(String name, FileInformationProvider<Object> provider); | ||
} |
83 changes: 83 additions & 0 deletions
83
src/main/java/de/dentrassi/rpm/builder/ListenableBuilderContext.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,83 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Fraunhofer-Institut fuer Optronik, Systemtechnik und Bildauswertung IOSB and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* Contributors: | ||
* Fraunhofer-Institut fuer Optronik, Systemtechnik und Bildauswertung IOSB - initial API and implementation | ||
*******************************************************************************/ | ||
package de.dentrassi.rpm.builder; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.ByteBuffer; | ||
import java.nio.file.Path; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.eclipse.packager.rpm.build.BuilderContext; | ||
import org.eclipse.packager.rpm.build.FileInformationProvider; | ||
|
||
public class ListenableBuilderContext implements BuilderContext { | ||
|
||
private final BuilderContext builderContext; | ||
private final Set<BuilderContextListener> listeners; | ||
|
||
public ListenableBuilderContext(BuilderContext builderContext) { | ||
this.builderContext = builderContext; | ||
this.listeners = new HashSet<>(); | ||
} | ||
|
||
@Override | ||
public void setDefaultInformationProvider(FileInformationProvider<Object> provider) { | ||
builderContext.setDefaultInformationProvider(provider); | ||
} | ||
|
||
@Override | ||
public FileInformationProvider<Object> getDefaultInformationProvider() { | ||
return builderContext.getDefaultInformationProvider(); | ||
} | ||
|
||
@Override | ||
public void addFile(String targetName, Path source, FileInformationProvider<? super Path> provider) throws IOException { | ||
builderContext.addFile(targetName, source, provider); | ||
listeners.forEach(listener -> listener.notifyFileAdded(targetName, (MojoFileInformationProvider) provider)); | ||
} | ||
|
||
@Override | ||
public void addFile(String targetName, InputStream source, FileInformationProvider<Object> provider) throws IOException { | ||
builderContext.addFile(targetName, source, provider); | ||
listeners.forEach(listener -> listener.notifyFileAdded(targetName, provider)); | ||
} | ||
|
||
@Override | ||
public void addFile(String targetName, ByteBuffer source, FileInformationProvider<Object> provider) throws IOException { | ||
builderContext.addFile(targetName, source, provider); | ||
listeners.forEach(listener -> listener.notifyFileAdded(targetName, provider)); | ||
} | ||
|
||
@Override | ||
public void addDirectory(String targetName, FileInformationProvider<? super Directory> provider) throws IOException { | ||
builderContext.addDirectory(targetName, provider); | ||
listeners.forEach(listener -> listener.notifyDirectoryAdded(targetName, (MojoFileInformationProvider) provider)); | ||
} | ||
|
||
@Override | ||
public void addSymbolicLink(String targetName, String linkTo, FileInformationProvider<? super SymbolicLink> provider) throws IOException { | ||
builderContext.addSymbolicLink(targetName, linkTo, provider); | ||
listeners.forEach(listener -> listener.notifySymbolicLinkAdded(targetName, (MojoFileInformationProvider) provider)); | ||
} | ||
|
||
public void registerListener(BuilderContextListener listener) { | ||
if (listener != null) { | ||
listeners.add(listener); | ||
} | ||
} | ||
|
||
public void removeListener(BuilderContextListener listener) { | ||
listeners.remove(listener); | ||
} | ||
|
||
} |
94 changes: 94 additions & 0 deletions
94
src/main/java/de/dentrassi/rpm/builder/MissingDirectoryTracker.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,94 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Fraunhofer-Institut fuer Optronik, Systemtechnik und Bildauswertung IOSB and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* Contributors: | ||
* Fraunhofer-Institut fuer Optronik, Systemtechnik und Bildauswertung IOSB - initial API and implementation | ||
*******************************************************************************/ | ||
package de.dentrassi.rpm.builder; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.eclipse.packager.rpm.build.BuilderContext; | ||
import org.eclipse.packager.rpm.build.FileInformationProvider; | ||
|
||
public class MissingDirectoryTracker implements BuilderContextListener { | ||
|
||
private final Set<String> explicitAddedDirectories; | ||
private final Map<String, FileInformationProvider<Object>> missingDirectories; | ||
private final List<String> ignorePrefixes; | ||
|
||
public MissingDirectoryTracker(List<String> ignorePrefixes) { | ||
this.explicitAddedDirectories = new HashSet<>(); | ||
this.missingDirectories = new HashMap<>(); | ||
this.ignorePrefixes = ignorePrefixes; | ||
} | ||
|
||
@Override | ||
public void notifyFileAdded(String targetName, FileInformationProvider<Object> provider) { | ||
addMissingDirectoriesFromPath(targetName, provider); | ||
} | ||
|
||
@Override | ||
public void notifyDirectoryAdded(String targetName, FileInformationProvider<Object> provider) { | ||
explicitAddedDirectories.add(targetName); | ||
missingDirectories.remove(targetName); | ||
addMissingDirectoriesFromPath(targetName, provider); | ||
} | ||
|
||
@Override | ||
public void notifySymbolicLinkAdded(String targetName, FileInformationProvider<Object> provider) { | ||
addMissingDirectoriesFromPath(targetName, provider); | ||
} | ||
|
||
private void addMissingDirectoriesFromPath(String targetName, FileInformationProvider<Object> provider) { | ||
for (String intermediateDirectory : getIntermediateDirectories(targetName)) { | ||
if (!shouldDirectoryIgnored(intermediateDirectory) && !explicitAddedDirectories.contains(intermediateDirectory)) { | ||
if (provider instanceof MojoFileInformationProvider) { | ||
MojoFileInformationProvider mojoProvider = (MojoFileInformationProvider) provider; | ||
missingDirectories.computeIfAbsent(intermediateDirectory, k -> new MojoFileInformationProvider(mojoProvider.getRulesetEval(), mojoProvider.getRuleId(), null, mojoProvider.getLogger(), mojoProvider.getTimestamp())); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private boolean shouldDirectoryIgnored(String directory) { | ||
for (String ignorePrefix : ignorePrefixes) { | ||
if (ignorePrefix.startsWith(directory)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public void addMissingIntermediateDirectoriesToContext(BuilderContext ctx) throws IOException { | ||
for (Map.Entry<String, FileInformationProvider<Object>> missingEntry : missingDirectories.entrySet()) { | ||
ctx.addDirectory(missingEntry.getKey(), missingEntry.getValue()); | ||
} | ||
} | ||
|
||
private List<String> getIntermediateDirectories(String targetName) { | ||
ArrayList<String> intermediateDirectories = new ArrayList<>(); | ||
Path path = Paths.get(targetName); | ||
|
||
for (int i = 1; i < path.getNameCount(); i++) { | ||
Path subPath = path.subpath(0, i); | ||
intermediateDirectories.add("/" + subPath); | ||
} | ||
|
||
return intermediateDirectories; | ||
} | ||
|
||
|
||
} |
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