-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1054 LIC: library-licensed-separately: support license import
retarget ImportLicenseDialog from a single license file to a directory Signed-off-by: eparovyshnaya <[email protected]>
- Loading branch information
1 parent
390a8e5
commit a37fc2b
Showing
5 changed files
with
146 additions
and
24 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
54 changes: 54 additions & 0 deletions
54
...c/org/eclipse/passage/lic/internal/jface/dialogs/licensing/AllConditionsFromLicenses.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,54 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.lic.internal.jface.dialogs.licensing; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
import org.eclipse.passage.lic.api.ServiceInvocationResult; | ||
import org.eclipse.passage.lic.api.conditions.ConditionPack; | ||
import org.eclipse.passage.lic.base.BaseServiceInvocationResult; | ||
import org.eclipse.passage.lic.base.SumOfCollections; | ||
import org.eclipse.passage.lic.equinox.LicenseReadingServiceRequest; | ||
import org.eclipse.passage.lic.internal.base.access.Libraries; | ||
import org.eclipse.passage.lic.internal.base.conditions.LicenseConditions; | ||
|
||
@SuppressWarnings("restriction") | ||
final class AllConditionsFromLicenses implements Supplier<ServiceInvocationResult<Collection<ConditionPack>>> { | ||
|
||
private final List<Path> licenses; | ||
private final Libraries libraries; | ||
private final LicenseReadingServiceRequest product; | ||
|
||
AllConditionsFromLicenses(List<Path> licenses, Libraries libraries) { | ||
this.licenses = licenses; | ||
this.libraries = libraries; | ||
this.product = new LicenseReadingServiceRequest(); | ||
} | ||
|
||
@Override | ||
public ServiceInvocationResult<Collection<ConditionPack>> get() { | ||
return licenses.stream()// | ||
.map(this::fromLicense)// | ||
.reduce(new BaseServiceInvocationResult.Sum<>(new SumOfCollections<>()))// | ||
.orElse(new BaseServiceInvocationResult<>(Collections.emptyList())); | ||
} | ||
|
||
private ServiceInvocationResult<Collection<ConditionPack>> fromLicense(Path file) { | ||
return new LicenseConditions(file, product, libraries).get(); | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
...e/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/AllLicensesFromFolder.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,68 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.lic.internal.jface.dialogs.licensing; | ||
|
||
import java.io.File; | ||
import java.io.FileFilter; | ||
import java.nio.file.Path; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
|
||
import org.eclipse.passage.lic.base.io.PassageFileExtension; | ||
|
||
final class AllLicensesFromFolder implements Supplier<List<Path>> { | ||
|
||
private final Optional<String> folder; | ||
|
||
AllLicensesFromFolder(String folder) { | ||
this(Optional.ofNullable(folder)); | ||
} | ||
|
||
AllLicensesFromFolder(Optional<String> folder) { | ||
this.folder = folder; | ||
} | ||
|
||
@Override | ||
public List<Path> get() { | ||
if (!folder.isPresent()) { | ||
return Collections.emptyList(); | ||
} | ||
return Arrays.stream(licenses())// | ||
.map(File::toPath)// | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private File[] licenses() { | ||
File host = new File(folder.get()); | ||
if (!host.isDirectory()) { | ||
return new File[0]; | ||
} | ||
return host.listFiles(licen()); | ||
} | ||
|
||
private FileFilter licen() { | ||
return new FileFilter() { | ||
private final PassageFileExtension licen = new PassageFileExtension.LicenseEncrypted(); | ||
|
||
@Override | ||
public boolean accept(File file) { | ||
return licen.ends(file); | ||
} | ||
}; | ||
} | ||
|
||
} |
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