-
-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BndEditor build.bnd: Plugin list should detect plugins by prefix #6069
Changes from 7 commits
0a2a187
f1afd01
e26a423
52c6d07
e7c3d39
1c28177
82a7abe
b9afac7
41546ac
3af8aaa
cd6147f
be40afa
4227195
52fa0ca
ff32e19
8fea6fc
ff243d1
2bd4290
5f30c39
55cd769
4ca991d
0cafeea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,14 @@ | |
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.Properties; | ||
import java.util.Set; | ||
import java.util.TreeMap; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import java.util.stream.StreamSupport; | ||
|
||
|
@@ -967,14 +969,117 @@ public void setTestSuites(List<String> suites) { | |
} | ||
|
||
public List<HeaderClause> getPlugins() { | ||
return doGetObject(Constants.PLUGIN, headerClauseListConverter); | ||
// return all plugins | ||
// we do prefix matching to support merged properties like | ||
// -plugin.1.Test, -plugin.2.Maven etc. | ||
try { | ||
Processor proc = getProperties(); | ||
Properties allProps = proc.getProperties(); | ||
Set<String> propertyKeys = proc.getPropertyKeys(true); | ||
|
||
List<HeaderClause> headers = propertyKeys.stream() | ||
.filter(p -> p.startsWith(Constants.PLUGIN)) | ||
.map(p -> headerClauseListConverter.convert(allProps.getProperty(p))) | ||
.flatMap(List::stream) | ||
.toList(); | ||
|
||
return headers; | ||
|
||
} catch (Exception e) { | ||
throw Exceptions.duck(e); | ||
} | ||
|
||
} | ||
|
||
public void setPlugins(List<HeaderClause> plugins) { | ||
List<HeaderClause> old = getPlugins(); | ||
doSetObject(Constants.PLUGIN, old, plugins, complexHeaderClauseListFormatter); | ||
} | ||
|
||
/** | ||
* Similar to {@link #getPlugins()} but returns a map where the key is the | ||
* property key of the bnd file e.g. | ||
* <code>-plugin.1.Test, -plugin.2.Maven </code> The value is a List of | ||
* plugins, although usually it is just a 1-element list. But it is also | ||
* possible to specify multiple plugins under a single key, thus it is a | ||
* list. | ||
* | ||
* @return a map with a property keys and their plugins. | ||
*/ | ||
public Map<String, List<MergedHeaderClause>> getPluginsProperties() { | ||
// return all plugins | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this logic should be moved to Processor, next to
We could even rewrite ( one day) the mergedProperties with this method. In the BndEditModel, you then turn each one into a number of constituent clauses that can be edited if the processor == the BndEditModel's processor. This would be similar to your MergedHeaderClause, but I would make it something like:
|
||
// we do prefix matching to support merged properties like | ||
// -plugin.1.Test, -plugin.2.Maven etc. | ||
|
||
try { | ||
Processor proc = getProperties(); | ||
Properties allProps = proc.getProperties(); | ||
Set<String> propertyKeys = proc.getPropertyKeys(true); | ||
|
||
|
||
Map<String, List<MergedHeaderClause>> map = new LinkedHashMap<>(); | ||
|
||
propertyKeys.stream() | ||
.filter(p -> p.startsWith(Constants.PLUGIN)) | ||
.forEach(key -> { | ||
|
||
boolean isLocal = doGetObject(key, headerClauseListConverter) != null; | ||
|
||
List<HeaderClause> headers = headerClauseListConverter.convert(allProps.getProperty(key)); | ||
map.put(key, headers.stream() | ||
.map(h -> new MergedHeaderClause(key, h, isLocal)) | ||
.collect(Collectors.toList())); | ||
|
||
}); | ||
|
||
return map; | ||
|
||
} catch (Exception e) { | ||
throw Exceptions.duck(e); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Updates and removes plugins. | ||
* | ||
* @param plugins | ||
* @param pluginPropKeysToRemove the property keys to remove (not modified, | ||
* caller needs to handle cleanup) | ||
*/ | ||
public void setPlugins(Map<String, List<MergedHeaderClause>> plugins, Collection<String> pluginPropKeysToRemove) { | ||
Map<String, List<MergedHeaderClause>> old = getPluginsProperties(); | ||
|
||
plugins.entrySet() | ||
.forEach(p -> { | ||
if (!p.getKey() | ||
.startsWith(Constants.PLUGIN)) { | ||
throw new IllegalArgumentException( | ||
"Plugin properties need to start with " + Constants.PLUGIN + ". Actual: " + p.getKey()); | ||
} | ||
|
||
List<HeaderClause> newLocalHeaders = p.getValue() | ||
.stream() | ||
.filter(mh -> mh.isLocal()) | ||
.map(mh -> mh.header()) | ||
.toList(); | ||
|
||
List<HeaderClause> oldLocalHeaders = old.get(p.getKey()) | ||
.stream() | ||
.filter(mh -> mh.isLocal()) | ||
.map(mh -> mh.header()) | ||
.toList(); | ||
|
||
doSetObject(p.getKey(), oldLocalHeaders, newLocalHeaders, | ||
complexHeaderClauseListFormatter); | ||
|
||
}); | ||
|
||
if (pluginPropKeysToRemove != null) { | ||
pluginPropKeysToRemove.forEach(key -> removeEntries(key)); | ||
} | ||
} | ||
|
||
public List<String> getPluginPath() { | ||
return doGetObject(Constants.PLUGINPATH, listConverter); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package aQute.bnd.build.model; | ||
|
||
import java.util.Objects; | ||
|
||
import aQute.bnd.build.model.clauses.HeaderClause; | ||
|
||
public record MergedHeaderClause(String key, HeaderClause header, boolean isLocal) { | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(header); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
MergedHeaderClause other = (MergedHeaderClause) obj; | ||
return Objects.equals(header, other.header); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -871,6 +871,23 @@ | |
description="Disable verification of server's X509 certificate (insecure, for testing only!)" /> | ||
</plugin> | ||
|
||
<plugin class="aQute.bnd.repository.maven.provider.MavenBndRepository" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had no idea this existed! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean those sections in the Yes, that is how I came to this PR? I was trying the +-Button of the Plugins list, because I wanted to see what this is... because I have never seen anything in the Plugins list of my build.bnd. And tadaaa I saw that I could add repositories. Unfortunately I did not see the MavenRepo we are using. We can later add also support for other repositories if needed. The xml I created from |
||
icon="icons/database.png" | ||
name="MavenBndRepository"> | ||
<property name="name" type="string" description="The name of this repository" /> | ||
<property name="releaseUrl" type="string" description="The urls to the remote release repository." /> | ||
<property name="stagingUrl" type="string" description="The url of the staging release repository." /> | ||
<property name="snapshotUrl" type="string" description="The urls to the remote snapshot repository." /> | ||
<property name="local" type="string" description="The path to the local repository" default="~/.m2/repository" /> | ||
<property name="readOnly" type="boolean" description="" default="false" /> | ||
<property name="index" type="string" description="The path to the index file" /> | ||
<property name="source" type="string" description="Content added to the index file. Content maybe one line without CR/LF as long as there is a comma or whitespace separating the GAVs. Further same format as the index file." /> | ||
<property name="noupdateOnRelease" type="boolean" description="Do not update the index when a file is released" /> | ||
<property name="poll_time" type="int" description="Sets the time in seconds when to check for changes in the pom-files" default="5" /> | ||
<property name="redeploy" type="boolean" description="Allow redeploy" /> | ||
<property name="ignore_metainf_maven" type="boolean" description="Ignore maven information in META-INF/maven/...." /> | ||
<property name="multi" type="string" description="Extensions for files that contain multiple JARs" /> | ||
</plugin> | ||
</extension> | ||
|
||
<extension point="org.eclipse.ui.intro.configExtension"> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this works with inheritance of properties & bnd file properties? It is a powerful but nasty problem
To make this work I think you need to model this as an object. When you edit a file, you can edit the local ones in the BndEditoModel but I think the inherited ones should be visible greyed out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have a call about this, so I do not misunderstand. The method
getPlugins()
and the newgetPluginsProperties()
I added work only locally.It looks like I could do
Set<String> propertyKeys = getProperties().getPropertyKeys(true);
to also get inherited properties (instead ofgetAllPropertyNames()
).To me it seems that the
BndEditModel
is designed for the local physical file you are looking at. If we would like to visualize inherited properties , we should talk about how this should look like. Greyed out in the same TableViewer could be an idea, but maybe it makes it more complicated, since you need to distinguish between local properties and inherited properties.Maybe an alternative idea would be an additional (collapsible if possible) non-editable TableViewer which only shows inherited stuff? That way we could treat it separately. Or we have a button saying "Show inherited" and then then all inherited plugins appear too, but editing is disabled?
Anyway, maybe I am misunderstanding or thinking too complicated :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have something in mind about your suggestion of
MergedProperty
class.Are you basically talking about something like
public List<HeaderClause> getPlugins() {..}
changing topublic List<MergedProperty> getPlugins() {..}
so that all the stuff which I currently do with the
Map<String, List<HeaderClause>>
happens under the hood + all the inheritance stuff?where
MergedProperty
has something like:String .getKey()
returns the local property key e.g. -plugin.1.MavenCentralList<HeaderClause> .getHeaders()
boolean .isInherited()
- returnsfalse
if it is only local.true
otherwiseList<MergedProperty> getParent()
- returns the parent which is inheritedSomething like this?
Can you also shed some more light in the meaning of the term
merged
here? I have the feeling I have not a good understanding of that at the moment. e.g. ismerging
referring to merging of theList<HeaderClause>
when they are defined under the same propertykey
?