Bug 272533 - Copyright statements are not generated.
Summary: Copyright statements are not generated.
Status: CLOSED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.5 M7   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-16 13:31 EDT by Paul Slauenwhite CLA
Modified: 2009-05-01 08:34 EDT (History)
5 users (show)

See Also:


Attachments
Screen capture showing JDOM's state (46.08 KB, image/gif)
2009-04-17 08:49 EDT, Ed Merks CLA
no flags Details
Test case I tried (2.24 KB, application/octet-stream)
2009-04-20 15:04 EDT, Olivier Thomann CLA
no flags Details
Patch for Util class (2.39 KB, patch)
2009-04-20 15:05 EDT, Olivier Thomann CLA
no flags Details | Diff
Changed test case (7.77 KB, application/octet-stream)
2009-04-21 16:05 EDT, Ed Merks CLA
no flags Details
Proposed fix (4.44 KB, patch)
2009-04-23 09:24 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Slauenwhite CLA 2009-04-16 13:31:37 EDT
Copyright statements are not generated.

Starting in JET 0.9.2 (EMF 2.5), the follow copyright statement in the skelton is not generated:

/**********************************************************************
 * Copyright (c) 2007, 2009 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
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: 
 * IBM - Initial API and implementation
 **********************************************************************/

Replacing the first line with the following seems to resolve the problem:

/*
Comment 1 Paul Elder CLA 2009-04-16 13:42:43 EDT
I need a bit more context. Where are you placing this copyright statement, and where do you expect it to appear?
Comment 3 Paul Elder CLA 2009-04-16 16:32:06 EDT
Moving this to EMF/Tools. You are using the JET version that is maintained by the EMF project.
Comment 4 Ed Merks CLA 2009-04-17 08:49:47 EDT
Created attachment 132230 [details]
Screen capture showing JDOM's state

The problem appears to be in JDOM itself.  The fHeader field is populated only when the /* */ header comment is used, not the header /** */ comment.
Comment 5 Olivier Thomann CLA 2009-04-17 08:55:07 EDT
Can you give more details on what you do to add the comment ?
JDOM is deprecated for a long time. It is time to move to ASTRewrite.
Comment 6 Ed Merks CLA 2009-04-17 12:06:41 EDT
Unfortunately the JDOM stuff is part of the JMerger's API, so we'd have to break the API to move. :-(

The thing ends up in this state, i.e., no fHeader field populated, directly from DOMFactory.createCompilationUnit.

Paul seems to suggest this is a regression, though who knows from how many years ago...
Comment 7 Paul Slauenwhite CLA 2009-04-17 12:32:57 EDT
(In reply to comment #6)
> Unfortunately the JDOM stuff is part of the JMerger's API, so we'd have to
> break the API to move. :-(
> 
> The thing ends up in this state, i.e., no fHeader field populated, directly
> from DOMFactory.createCompilationUnit.
> 
> Paul seems to suggest this is a regression, though who knows from how many
> years ago...
> 

Yes, we saw this change when moving from EMF 2.2.4 to EMF 2.4.2.
Comment 8 Dave Steinberg CLA 2009-04-17 12:46:08 EDT
The context here isn't completely clear, so forgive me if this is misguided, but I figured I'd throw it out there...

Is Paul in a position to move to our newer AST-based JMerge implementation? Shouldn't it be just a matter of passing an instance of ASTFacadeHelper to JControlModel.initialize()?
Comment 9 Ed Merks CLA 2009-04-17 13:00:15 EDT
Dave,

No, I was a bit confused about it too.  I really do wish folks would provide more details...

It's not a JMerger issue at all.  It's JETSkeleton that's doing the work.  It's certainly feasibly for it to use the merger facade stuff, but we'd have to break the API...
Comment 10 Olivier Thomann CLA 2009-04-17 13:10:51 EDT
If I can know what is used in the JDOM API to create this issue, I might be able to work on a fix.
JDOM has not changed for months, maybe years.
Comment 11 Ed Merks CLA 2009-04-17 13:18:17 EDT
Below is the class.  I think if you create a complication unit, and say add an import, then you should see the problem...



/**
 * <copyright>
 *
 * Copyright (c) 2002-2006 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
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: 
 *   IBM - Initial API and implementation
 *
 * </copyright>
 *
 * $Id: JETSkeleton.java,v 1.10 2007/05/15 22:32:34 emerks Exp $
 */
package org.eclipse.emf.codegen.jet;


import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.jdt.core.jdom.DOMFactory;
import org.eclipse.jdt.core.jdom.IDOMCompilationUnit;
import org.eclipse.jdt.core.jdom.IDOMMethod;
import org.eclipse.jdt.core.jdom.IDOMNode;


/**
 */
@SuppressWarnings("deprecation")
public class JETSkeleton 
{
  protected final String NL = System.getProperties().getProperty("line.separator");

  protected final String SKELETON_COMPILATION_UNIT = 
    "public class CLASS" + NL + "{" + NL + "  public String generate(Object argument)" + NL + "  {" + NL + "    return \"\";" + NL + "  }" + NL + "}" + NL;

  protected final String STATIC_NL_DECLARATION = "  protected static String nl;" + NL;
  protected final String CREATE_METHOD_DECLARATION_HEAD = "  public static synchronized ";
  protected final String CREATE_METHOD_DECLARATION_MIDDLE = " create(String lineSeparator)" + NL + "  {" + NL + "    nl = lineSeparator;" + NL + "    ";
  protected final String CREATE_METHOD_DECLARATION_MIDDLE2 = " result = new ";
  protected final String CREATE_METHOD_DECLARATION_TAIL = "();" + NL + "    nl = null;" + NL + "    return result;" + NL + "  }" + NL + NL;
  
  protected final String NL_DECLARATION = "  public final String NL = nl == null ? (";
  protected final String NL_DECLARATION_TAIL = ") : nl;" + NL;
  protected final String STRING_BUFFER_DECLARATION = "    final StringBuffer stringBuffer = new StringBuffer();" + NL;
  protected final String STRING_BUFFER_RETURN = "    return stringBuffer.toString();" + NL;

  protected DOMFactory jdomFactory = new DOMFactory();
  protected IDOMCompilationUnit compilationUnit;
  protected String nlString = "System.getProperties().getProperty(\"line.separator\")";

  /**
   */
  public JETSkeleton() 
  {
    compilationUnit = jdomFactory.createCompilationUnit(SKELETON_COMPILATION_UNIT, "CLASS");
  }
  
  public String getCompilationUnitContents()
  {
    return compilationUnit.getContents();
  }

  public IDOMCompilationUnit getCompilationUnit()
  {
    return compilationUnit;
  }

  public void setCompilationUnitContents(String contents)
  {
    compilationUnit = jdomFactory.createCompilationUnit(convertLineFeed(contents), "CLASS");
  }

  public String getNLString()
  {
    return nlString;
  }

  public void setNLString(String nlString)
  {
    this.nlString = nlString;
  }

  public String getPackageName() 
  {
    for (IDOMNode node = compilationUnit.getFirstChild(); node != null; node = node.getNextNode())
    {
      if (node.getNodeType() == IDOMNode.PACKAGE)
      {
        return node.getName();
      }
    }

    return "";
  }

  public void setPackageName(String packageName) 
  {
    for (IDOMNode node = compilationUnit.getFirstChild(); node != null; node = node.getNextNode())
    {
      if (node.getNodeType() == IDOMNode.PACKAGE)
      {
        node.setName(packageName);
        return;
      }
    }

    compilationUnit.getFirstChild().insertSibling(jdomFactory.createPackage("package " + packageName + ";" + NL + NL));
  }

  public void setConstants(List<String> constants)
  {
    for (IDOMNode node = compilationUnit.getFirstChild(); node != null; node = node.getNextNode())
    {
      if (node.getNodeType() == IDOMNode.TYPE)
      {
        String name = node.getName();
        IDOMNode insertionNode = node.getFirstChild();
        insertionNode.insertSibling(jdomFactory.createField(STATIC_NL_DECLARATION));
        insertionNode.insertSibling
          (jdomFactory.createMethod
              (CREATE_METHOD_DECLARATION_HEAD + name + 
                  CREATE_METHOD_DECLARATION_MIDDLE + name + 
                  CREATE_METHOD_DECLARATION_MIDDLE2 + name + 
                  CREATE_METHOD_DECLARATION_TAIL));
        insertionNode.insertSibling(jdomFactory.createField(NL_DECLARATION + getNLString() + NL_DECLARATION_TAIL));
        for (Iterator<String> i = constants.iterator(); i.hasNext(); )
        {
          String constant = "  " + i.next() + NL;
          if (!i.hasNext())
          {
            constant += NL;
          }
          insertionNode.insertSibling(jdomFactory.createField(constant));
        }
        break;
      }
    }
  }
  public void setBody(List<String> lines)
  {
    IDOMMethod method = getLastMethod();
    if (method != null)
    {
      StringBuffer body = new StringBuffer();
      body.append(NL + "  {" + NL);
      body.append(STRING_BUFFER_DECLARATION);
      for (String line : lines)
      {
        body.append("    ");
        body.append(convertLineFeed(line));
        body.append(NL);
      }
      body.append(STRING_BUFFER_RETURN);
      body.append("  }" + NL);

      method.setBody(body.toString());
    }
  }

  protected static final Pattern NL_PATTERN = Pattern.compile("([\\n][\\r]?|[\\r][\\n]?)", Pattern.MULTILINE);
  
  public String convertLineFeed(String value)
  {
    Matcher matcher = NL_PATTERN.matcher(value);
    if (matcher.find())
    {
      String nl = matcher.group(1);  
      if (!NL.equals(nl))
      {
        return value.replaceAll(nl, NL);
      }
    }
    
    return value;
  }

  public String getMethodName() 
  {
    IDOMMethod method = getLastMethod();
    if (method != null)
    {
      return method.getName();
    }
    else
    {
      return "";
    }
  }

  public void addImports(String importList)
  {
    for (IDOMNode node = compilationUnit.getFirstChild(); node != null; node = node.getNextNode())
    {
      if (node.getNodeType() == IDOMNode.TYPE)
      {
        for (StringTokenizer stringTokenizer = new StringTokenizer(importList, " \t\n\r"); stringTokenizer.hasMoreTokens(); )
        {
          String token = stringTokenizer.nextToken();
          String newImport = "import " + token + ";" + NL;
          if (!stringTokenizer.hasMoreTokens())
          {
            newImport += NL;
          }
          node.insertSibling(jdomFactory.createImport(newImport));
        }
        return;
      }
    }
  }

  public String getClassName() 
  {
    for (IDOMNode node = compilationUnit.getFirstChild(); node != null; node = node.getNextNode())
    {
      if (node.getNodeType() == IDOMNode.TYPE)
      {
        return node.getName();
      }
    }

    return null;
  }

  public void setClassName(String className) 
  {
    for (IDOMNode node = compilationUnit.getFirstChild(); node != null; node = node.getNextNode())
    {
      if (node.getNodeType() == IDOMNode.TYPE)
      {
        node.setName(className);
      }
    }
  }

  protected IDOMMethod getLastMethod()
  {
    IDOMMethod method = null;
    for (IDOMNode node = compilationUnit.getFirstChild(); node != null; node = node.getNextNode())
    {
      if (node.getNodeType() == IDOMNode.TYPE)
      {
        for (IDOMNode child = node.getFirstChild(); child != null; child = child.getNextNode())
        {
          if (child.getNodeType() == IDOMNode.METHOD)
          {
            method = (IDOMMethod)child;
          }
        }
      }
    }
    return method;
  }
}
Comment 12 Olivier Thomann CLA 2009-04-20 15:04:47 EDT
Created attachment 132480 [details]
Test case I tried

If you take the test case from the attached zip file, every thing seens to run ok.

I patched the Util method that returns the line.separator in order to support the run outside an headless environment. I'll attach the corresponding patch next.
Comment 13 Olivier Thomann CLA 2009-04-20 15:05:07 EDT
Created attachment 132481 [details]
Patch for Util class
Comment 14 Olivier Thomann CLA 2009-04-20 15:05:47 EDT
As soon as I can reproduce this issue, I can have a look and try to provide a fix for it.
Comment 15 Paul Slauenwhite CLA 2009-04-21 07:29:38 EDT
(In reply to comment #12)
> Created an attachment (id=132480) [details]
> Test case I tried
> 
> If you take the test case from the attached zip file, every thing seens to run
> ok.
> 
> I patched the Util method that returns the line.separator in order to support
> the run outside an headless environment. I'll attach the corresponding patch
> next.
> 

Will this patch work with the following first line:

/**********************************************************************

The existing code will work if we use '/*' (without signle quotes) but not with additional asterisks.
Comment 16 Olivier Thomann CLA 2009-04-21 12:47:25 EDT
(In reply to comment #15)
> Will this patch work with the following first line:
> /**********************************************************************
> The existing code will work if we use '/*' (without signle quotes) but not with
> additional asterisks.
I could not reproduce the problem so far.
I posted a test case I tried and it seems to work fine.
How is the copyright statement set on the unit ?
Comment 17 Paul Slauenwhite CLA 2009-04-21 13:08:26 EDT
(In reply to comment #16)
> (In reply to comment #15)
> > Will this patch work with the following first line:
> > /**********************************************************************
> > The existing code will work if we use '/*' (without signle quotes) but not with
> > additional asterisks.
> I could not reproduce the problem so far.
> I posted a test case I tried and it seems to work fine.
> How is the copyright statement set on the unit ?
> 

Please extract the following plug-ins to your Eclipse 3.5 M6 workspace:

http://dev.eclipse.org/viewcvs/index.cgi/test/org.eclipse.hyades.test.tools.core/?root=TPTP_Project

http://dev.eclipse.org/viewcvs/index.cgi/test/org.eclipse.hyades.test.core/?root=TPTP_Project

Note the generated class (/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenSuiteMethod.java) does not contain the copyright in the template (/org.eclipse.hyades.test.tools.core/templates_java/SuiteMethod.skeleton).
Comment 18 Olivier Thomann CLA 2009-04-21 13:37:56 EDT
(In reply to comment #17)
> Please extract the following plug-ins to your Eclipse 3.5 M6 workspace:
> http://dev.eclipse.org/viewcvs/index.cgi/test/org.eclipse.hyades.test.tools.core/?root=TPTP_Project
> http://dev.eclipse.org/viewcvs/index.cgi/test/org.eclipse.hyades.test.core/?root=TPTP_Project
> Note the generated class
> (/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenSuiteMethod.java)
> does not contain the copyright in the template
> (/org.eclipse.hyades.test.tools.core/templates_java/SuiteMethod.skeleton).
Would you have a psf file to check out all required bundles from the CVS repository?
Comment 19 Paul Slauenwhite CLA 2009-04-21 13:40:13 EDT
(In reply to comment #18)
> (In reply to comment #17)
> > Please extract the following plug-ins to your Eclipse 3.5 M6 workspace:
> > http://dev.eclipse.org/viewcvs/index.cgi/test/org.eclipse.hyades.test.tools.core/?root=TPTP_Project
> > http://dev.eclipse.org/viewcvs/index.cgi/test/org.eclipse.hyades.test.core/?root=TPTP_Project
> > Note the generated class
> > (/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenSuiteMethod.java)
> > does not contain the copyright in the template
> > (/org.eclipse.hyades.test.tools.core/templates_java/SuiteMethod.skeleton).
> Would you have a psf file to check out all required bundles from the CVS
> repository?
> 

All TPTP plug-ins:
http://www.eclipse.org/tptp/home/documents/resources/projectSets/TPTPProjectSet460-pserver.psf

Comment 20 Ed Merks CLA 2009-04-21 16:05:56 EDT
Created attachment 132664 [details]
Changed test case

This is behaving differently from the example I was debugger before, but definitely seems to be demonstrating similar odd behavior.
Comment 21 Olivier Thomann CLA 2009-04-22 13:31:38 EDT
Ok, thanks Ed.
Your example exhibits the wrong behavior. I am investigating.
Comment 22 Olivier Thomann CLA 2009-04-22 13:35:48 EDT
In fact this last test case is even worse than the original test case. Replace the first line with "/*" still removes the header comment.
Comment 23 Ed Merks CLA 2009-04-22 13:48:30 EDT
Yes, that was my point about it not being quite the same...
Comment 24 Olivier Thomann CLA 2009-04-22 15:04:56 EDT
I might have a fix for it.
I am trying to create the workspace with all TPTP and EMF in order to verify that it works with the template specified in comment 17.
Comment 25 Olivier Thomann CLA 2009-04-23 09:20:10 EDT
I believe I have a fix for this. It seems to work fine using the example in comment 17.
If I release that code, could someone confirm this is working as expected without any regression?
We don't have many tests for this deprecated code.
Comment 26 Olivier Thomann CLA 2009-04-23 09:24:04 EDT
Created attachment 132926 [details]
Proposed fix
Comment 27 Paul Slauenwhite CLA 2009-04-23 09:35:33 EDT
(In reply to comment #25)
> I believe I have a fix for this. It seems to work fine using the example in
> comment 17.
> If I release that code, could someone confirm this is working as expected
> without any regression?
> We don't have many tests for this deprecated code.
> 

Sure.
Comment 28 Ed Merks CLA 2009-04-23 10:51:13 EDT
All our tests still pass and the scenario that was failing before is working properly now, so it looks good.
Comment 29 Olivier Thomann CLA 2009-04-23 10:52:34 EDT
Thanks for checking.
I am releasing for next build.
Comment 30 Olivier Thomann CLA 2009-04-23 10:55:28 EDT
I'll try to build a regression test before releasing the fix.
Comment 31 Olivier Thomann CLA 2009-04-23 11:58:17 EDT
Released for 3.5M7.
In order to verify, a workspace that is using TPTP must be used to reproduce the problem mentionned in comment 17.
Comment 32 David Audel CLA 2009-04-29 11:18:59 EDT
Verified for 3.5M7 (Verified by reporter)
Comment 33 Paul Slauenwhite CLA 2009-05-01 08:34:34 EDT
Verified using the following:

eclipse-SDK-I20090429-1800-win32.zip
emf-runtime-I200904281800.zip
tptp.sdk-TPTP-4.6.0-200904300100.zip
xsd-runtime-I200904281800.zip

Closing.