use of org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile in project linuxtools by eclipse.
the class SpecfileSource method changeDeclaration.
public void changeDeclaration(int oldPatchNumber) {
Specfile specfile = this.getSpecfile();
Pattern patchPattern;
if (oldPatchNumber == 0) {
// $NON-NLS-1$ //$NON-NLS-2$
patchPattern = Pattern.compile("Patch" + oldPatchNumber + "|Patch");
} else {
// $NON-NLS-1$
patchPattern = Pattern.compile("Patch" + oldPatchNumber);
}
String line;
try {
line = specfile.getLine(lineNumber);
Matcher patchMatcher = patchPattern.matcher(line);
if (!patchMatcher.find()) {
// TODO: Maybe we can throw a exception here.
// $NON-NLS-1$
System.out.println(Messages.getString("SpecfileSource.2") + patchPattern.pattern());
}
// $NON-NLS-1$
specfile.changeLine(lineNumber, line.replaceAll(patchPattern.pattern(), "Patch" + number));
} catch (BadLocationException e) {
SpecfileLog.logError(e);
}
}
use of org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile in project linuxtools by eclipse.
the class FileTestCase method setUp.
@Before
public void setUp() throws CoreException {
testProject = new SpecfileTestProject();
String fileName = "test" + this.getClass().getSimpleName() + ".spec";
testFile = testProject.createFile(fileName);
editor = new SpecfileEditor();
parser = new SpecfileParser();
specfile = new Specfile();
}
use of org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile in project linuxtools by eclipse.
the class SpecfileEditorDownloadSourcesActionDelegate method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final Shell shell = HandlerUtil.getActiveShellChecked(event);
final SpecfileParser specparser = new SpecfileParser();
final IResource resource = RPMHandlerUtils.getResource(event);
final RPMProject rpj = RPMHandlerUtils.getRPMProject(resource);
final IFile workFile = (IFile) rpj.getSpecFile();
final Specfile specfile = workFile != null ? specparser.parse(workFile) : null;
// retrieve source(s) from specfile
final List<SpecfileSource> sourceURLList = specfile != null ? (List<SpecfileSource>) specfile.getSources() : null;
// currently stops immediately once an invalid source URL is encountered
for (final SpecfileSource sourceurls : sourceURLList) {
try {
String rawURL = sourceurls.getFileName();
String resolvedURL = UiUtils.resolveDefines(specfile, rawURL);
URL url = null;
try {
url = new URL(resolvedURL);
} catch (MalformedURLException e) {
SpecfileLog.logError(NLS.bind(Messages.DownloadSources_malformedURL, resolvedURL), e);
// $NON-NLS-1$
RPMUtils.showErrorDialog(// $NON-NLS-1$
shell, // $NON-NLS-1$
"Error", NLS.bind(Messages.DownloadSources_malformedURL, resolvedURL));
return null;
}
URLConnection connection = url.openConnection();
if (!(connection instanceof HttpURLConnection) || ((HttpURLConnection) connection).getResponseCode() != HttpURLConnection.HTTP_NOT_FOUND) {
connection.connect();
// grab the name of the file from the URL
// $NON-NLS-1$
int offset = url.toString().lastIndexOf("/");
String filename = url.toString().substring(offset + 1);
// create the path to the "to be downloaded" file
IFile file = rpj.getConfiguration().getSourcesFolder().getFile(new Path(filename));
Job downloadJob = new DownloadJob(file, connection);
downloadJob.setUser(true);
downloadJob.schedule();
}
} catch (IOException e) {
SpecfileLog.logError(Messages.DownloadSources_cannotConnectToURL, e);
// $NON-NLS-1$
RPMUtils.showErrorDialog(// $NON-NLS-1$
shell, // $NON-NLS-1$
"Error", Messages.DownloadSources_cannotConnectToURL);
return null;
}
}
return null;
}
Aggregations