aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeo Ufimtsev2014-07-25 16:43:02 (EDT)
committerDavid Williams2014-07-26 11:34:30 (EDT)
commit0834385d36432020db4288e27e8ae4309b4e11a2 (patch)
treeb9ca211b7bce7bd1bfcecc0d341cd307c0616c5c
parent10ea8bdd6789dc384f19c42c52bf6ba08f277ccd (diff)
downloadeclipse.platform.releng-0834385d36432020db4288e27e8ae4309b4e11a2.zip
eclipse.platform.releng-0834385d36432020db4288e27e8ae4309b4e11a2.tar.gz
eclipse.platform.releng-0834385d36432020db4288e27e8ae4309b4e11a2.tar.bz2
bug 276253 - 'fix copyright' inserts notice above bashscript header.refs/changes/37/30537/2
Fix Copyright inserts the copyright notice above the bash script header, causing bash scripts to break. This fix reads the bash script, identifies if it has a header and if so inserts the copyright note below the header. Fix implemented by: Gunnar Wagenknecht Change-Id: Ie34f4b8b4a0d1cc151760808d72c6fda91127e8b Signed-off-by: Leo Ufimtsev <lufimtse@redhat.com>
-rw-r--r--bundles/org.eclipse.releng.tools/META-INF/MANIFEST.MF3
-rw-r--r--bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/ShellMakeFile.java53
2 files changed, 54 insertions, 2 deletions
diff --git a/bundles/org.eclipse.releng.tools/META-INF/MANIFEST.MF b/bundles/org.eclipse.releng.tools/META-INF/MANIFEST.MF
index 3c5c450..bafaa63 100644
--- a/bundles/org.eclipse.releng.tools/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.releng.tools/META-INF/MANIFEST.MF
@@ -22,7 +22,8 @@ Require-Bundle: org.eclipse.ui.ide;resolution:=optional,
org.eclipse.compare,
org.eclipse.ui.console,
org.eclipse.jgit;bundle-version="1.3.0";resolution:=optional,
- org.eclipse.egit.core;bundle-version="1.3.0";resolution:=optional
+ org.eclipse.egit.core;bundle-version="1.3.0";resolution:=optional,
+ org.eclipse.text
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package:
diff --git a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/ShellMakeFile.java b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/ShellMakeFile.java
index 72753da..e8bb4e8 100644
--- a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/ShellMakeFile.java
+++ b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/ShellMakeFile.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,12 +8,16 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Martin Oberhuber (Wind River) - [235572] detect existing comments in bat files
+ * Leo Ufimtsev adding fix of : Gunnar Wagenknecht (wagenknecht) - [276253] detect '#!/bin/sh' header.
*******************************************************************************/
package org.eclipse.releng.tools;
+import java.io.IOException;
import java.util.regex.Pattern;
import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
public class ShellMakeFile extends SourceFile {
@@ -47,4 +51,51 @@ public class ShellMakeFile extends SourceFile {
return CopyrightComment.SHELL_MAKE_COMMENT;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.releng.tools.SourceFile#doInsert(java.lang.String, org.eclipse.jface.text.IDocument)
+ */
+ protected void doInsert(final String comment, IDocument document) throws BadLocationException, IOException {
+ // find insert offset (we must skip instructions)
+ int insertOffset = findInsertOffset(document);
+
+ // insert comment
+ document.replace(insertOffset, 0, comment);
+ }
+
+ private int findInsertOffset(IDocument document) throws BadLocationException {
+ boolean inInstruction = false;
+ int insertOffset = 0;
+
+ for (int offset = 0; offset < document.getLength(); offset++) {
+ char c = document.getChar(offset);
+
+ // also look at next char
+ char c2 = ((offset + 1) < document.getLength()) ? document.getChar(offset + 1) : 0;
+
+ // look for line ending
+ if (inInstruction) {
+ if (c == '\n' && c2 == '\r' || c == '\r' && c2 == '\n') {
+ insertOffset = offset + 2;
+ break; // done
+ } else if (c == '\n') {
+ insertOffset = offset + 1;
+ break; // done
+ } else {
+ // continue looking for ending
+ continue;
+ }
+ }
+
+ // next chars must start an instruction
+ if (c == '#' && c2 == '!') {
+ inInstruction = true;
+ offset++; // don't need to analyse c2 again
+ continue;
+ } else {
+ // if it's something else, we can stop seeking
+ break;
+ }
+ }
+ return insertOffset;
+ }
}