forked from eclipse-4diac/4diac-ide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request eclipse-4diac#92 from eclipse-4diac/freeze
Merge Freeze back to Develop
- Loading branch information
Showing
28 changed files
with
678 additions
and
122 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
80 changes: 80 additions & 0 deletions
80
...lipse.fordiac.ide.ant/src_ant/org/eclipse/fordiac/ide/ant/ant/ExportProjectLibraries.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,80 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Primetals Technologies Austria GmbH | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Patrick Aigner | ||
* - initial API and implementation and/or initial documentation | ||
*******************************************************************************/ | ||
package org.eclipse.fordiac.ide.ant.ant; | ||
|
||
import org.apache.tools.ant.BuildException; | ||
import org.apache.tools.ant.Task; | ||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.resources.IWorkspace; | ||
import org.eclipse.core.resources.ResourcesPlugin; | ||
import org.eclipse.fordiac.ide.library.model.library.Manifest; | ||
import org.eclipse.fordiac.ide.library.model.util.ManifestHelper; | ||
|
||
public class ExportProjectLibraries extends Task { | ||
private static final String ANT_EXPORT_TASK_DIRECTORY_NAME = "exported_FBs"; //$NON-NLS-1$ | ||
|
||
private String projectName; | ||
private String exportDirectory = ANT_EXPORT_TASK_DIRECTORY_NAME; | ||
private boolean exportCMakeList = false; | ||
private boolean preserveDirectoryStructure = false; | ||
|
||
public void setProjectName(final String value) { | ||
projectName = value; | ||
} | ||
|
||
public void setExportDirectory(final String value) { | ||
exportDirectory = value; | ||
} | ||
|
||
public void setExportCMakeList(final boolean value) { | ||
exportCMakeList = value; | ||
} | ||
|
||
public void setPreserveDirectoryStructure(final boolean preserveDirectoryStructure) { | ||
this.preserveDirectoryStructure = preserveDirectoryStructure; | ||
} | ||
|
||
@Override | ||
public void execute() throws BuildException { | ||
if (projectName == null) { | ||
throw new BuildException("Project name not specified!"); //$NON-NLS-1$ | ||
} | ||
final IWorkspace workspace = ResourcesPlugin.getWorkspace(); | ||
final IProject fordiacProject = workspace.getRoot().getProject(projectName); | ||
|
||
final Manifest manifest = ManifestHelper.getContainerManifest(fordiacProject); | ||
if (manifest == null) { | ||
throw new BuildException("Project named '" + projectName + "' lacks a manifest file"); //$NON-NLS-1$ //$NON-NLS-2$ | ||
} | ||
if (manifest.getExports() == null) { | ||
throw new BuildException("No exports present in manifest file"); //$NON-NLS-1$ | ||
} | ||
if (manifest.getExports().getLibrary().isEmpty()) { | ||
throw new BuildException("No libraries defined in manifest file"); //$NON-NLS-1$ | ||
} | ||
|
||
manifest.getExports().getLibrary().forEach(lib -> { | ||
final ExportProjectLibrary libexport = new ExportProjectLibrary(); | ||
libexport.setProjectName(projectName); | ||
libexport.setExportDirectory(exportDirectory); | ||
libexport.setExportCMakeList(exportCMakeList); | ||
libexport.setPreserveDirectoryStructure(preserveDirectoryStructure); | ||
libexport.setSymbolicName(lib.getSymbolicName()); | ||
|
||
log("Exporting library: " + lib.getSymbolicName()); //$NON-NLS-1$ | ||
libexport.execute(); | ||
}); | ||
} | ||
|
||
} |
122 changes: 122 additions & 0 deletions
122
...eclipse.fordiac.ide.ant/src_ant/org/eclipse/fordiac/ide/ant/ant/ExportProjectLibrary.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,122 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Primetals Technologies Austria GmbH | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Patrick Aigner | ||
* - initial API and implementation and/or initial documentation | ||
*******************************************************************************/ | ||
package org.eclipse.fordiac.ide.ant.ant; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
|
||
import org.apache.tools.ant.BuildException; | ||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.core.runtime.IPath; | ||
import org.eclipse.core.runtime.Path; | ||
import org.eclipse.fordiac.ide.library.model.library.Library; | ||
import org.eclipse.fordiac.ide.library.model.library.Manifest; | ||
import org.eclipse.fordiac.ide.library.model.util.ManifestHelper; | ||
import org.eclipse.fordiac.ide.model.typelibrary.TypeLibrary; | ||
import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryManager; | ||
|
||
public class ExportProjectLibrary extends AbstractExportFBs { | ||
private static String starPattern = "(_[a-zA-Z0-9]|[a-zA-Z])(_?[a-zA-Z0-9])*"; //$NON-NLS-1$ | ||
private static String doubleStarPattern = starPattern + "(::" + starPattern + ")*"; //$NON-NLS-1$ //$NON-NLS-2$ | ||
private static Pattern replacePattern = Pattern.compile("\\*\\*|\\*"); //$NON-NLS-1$ | ||
|
||
private String symbolicName; | ||
private List<Pattern> includePatterns; | ||
private List<Pattern> excludePatterns; | ||
private TypeLibrary typelib; | ||
|
||
public void setSymbolicName(final String symbolicName) { | ||
this.symbolicName = symbolicName; | ||
} | ||
|
||
@Override | ||
protected File getDirectory() { | ||
return new File(getFordiacProject().getLocationURI()); | ||
} | ||
|
||
@Override | ||
protected String getSingleFBName() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected List<String> getExcludeSubfolder() { | ||
return new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
protected void checkFordiacProject() { | ||
super.checkFordiacProject(); | ||
final Manifest manifest = ManifestHelper.getContainerManifest(getFordiacProject()); | ||
if (manifest == null) { | ||
throw new BuildException("Project named '" + getProjectNameString() + "' lacks a manifest file"); //$NON-NLS-1$ //$NON-NLS-2$ | ||
} | ||
if (manifest.getExports() == null) { | ||
throw new BuildException("No exports present in manifest file"); //$NON-NLS-1$ | ||
} | ||
final Library library = manifest.getExports().getLibrary().stream() | ||
.filter(lib -> lib.getSymbolicName().equals(symbolicName)).findFirst().orElse(null); | ||
if (library == null) { | ||
throw new BuildException("Library export named '" + symbolicName + "' not present in manifest file"); //$NON-NLS-1$ //$NON-NLS-2$ | ||
} | ||
setExportDirectory(exportDirectory + File.separator + symbolicName); | ||
|
||
includePatterns = new ArrayList<>(); | ||
excludePatterns = new ArrayList<>(); | ||
typelib = TypeLibraryManager.INSTANCE.getTypeLibrary(getFordiacProject()); | ||
|
||
library.getIncludes().getLibraryElement().forEach(elem -> { | ||
includePatterns.add(createPattern(elem.getValue())); | ||
}); | ||
|
||
library.getExcludes().getLibraryElement().forEach(elem -> { | ||
excludePatterns.add(createPattern(elem.getValue())); | ||
}); | ||
} | ||
|
||
@Override | ||
protected List<File> getFBsFiles(final List<File> files, final File dir, final String singleFBName, | ||
final List<String> excludeSubfolder) { | ||
|
||
if (!dir.isDirectory() && isFilteredFiletype(dir)) { | ||
final IPath location = Path.fromOSString(dir.getAbsolutePath()); | ||
final IFile ifile = workspace.getRoot().getFileForLocation(location); | ||
final String typename = typelib.getTypeEntry(ifile).getFullTypeName(); | ||
if (includePatterns.stream().anyMatch(p -> p.matcher(typename).matches()) | ||
&& excludePatterns.stream().noneMatch(p -> p.matcher(typename).matches())) { | ||
files.add(dir); | ||
} | ||
return files; | ||
} | ||
if (dir.listFiles() != null) { | ||
for (final File file : dir.listFiles()) { | ||
getFBsFiles(files, file, singleFBName, excludeSubfolder); | ||
} | ||
} | ||
|
||
return files; | ||
} | ||
|
||
private static Pattern createPattern(final String raw) { | ||
final String p = replacePattern.matcher(raw).replaceAll(match -> { | ||
if (match.end() - match.start() > 1) { | ||
return doubleStarPattern; | ||
} | ||
return starPattern; | ||
}); | ||
return Pattern.compile(p); | ||
} | ||
} |
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.