Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Add sed script for Seam->CDI annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Jun 23, 2015
1 parent b858314 commit 47fdf84
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions etc/scripts/seam2cdi.sh
@@ -0,0 +1,92 @@
#!/bin/bash -e

# Copyright 2015, Red Hat, Inc. and individual contributors as indicated by the
# @author tags. See the copyright.txt file in the distribution for a full
# listing of individual contributors.
#
# This is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# This software is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this software; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
# site: http://www.fsf.org.


#########################################################################
# seam2cdi.sh, Sean Flanigan sflaniga@redhat.com
#
# Quick and dirty migration of Seam annotations to CDI equivalents.
#
#########################################################################
# Requirements:
# A modern bash
# GNU sed
#########################################################################
# To use this script:
# $ shopt -s globstar
# $ etc/scripts/seam2cdi.sh **/src/**/*.java **/src/**/*.groovy
#
# Note: Seam components (POJOs) with no declared scope (ie Event scope)
# will become @Dependent by default, not @RequestScoped. Our unscoped
# components all appear to be stateless services, so this should be okay.
#########################################################################

# NB here-doc indentation must use tab!
sed -i "$@" -f - <<-EOF
s/org.jboss.seam.annotations.In;/javax.inject.Inject;/g
s/org.jboss.seam.annotations.In$/javax.inject.Inject/g
s/import org.jboss.seam.annotations.Install;/import org.apache.deltaspike.core.api.exclude.Exclude;\nimport org.apache.deltaspike.core.api.projectstage.ProjectStage;/g
s|@Install(false)|@Exclude(ifProjectStage = ProjectStage.UnitTest.class) /* TODO [CDI] Set ProjectStage for unit tests */|g
s/@In("applicationConfiguration")/@Inject/g
s/@In("blobPersistService")/@Inject/g
s/@In("commonMarkRenderer")/@Inject/g
s/@In("event")/@Inject/g
s/@In("filePersistService")/@Inject/g
s/@In("jsfMessages")/@Inject/g
s/@In("localeServiceImpl")/@Inject/g
s/@In("textFlowTargetDAO")/@Inject/g
s/@In("translationMemoryServiceImpl")/@Inject/g
s/@In(create = true)/@Inject/g
s|^\( \+\)@In(\(.*\))|\1@Inject /* TODO [CDI] check this: migrated from @In(\2) */|g
s/@In(/@Inject(/g
s/@In /@Inject /g
s/@In$/@Inject/g
s/org.jboss.seam.annotations.Name/javax.inject.Named/g
s/@Name(/@Named(/g
/import org.jboss.seam.ScopeType;\?/d
/import org.jboss.seam.annotations.Scope;\?/d
s/@Scope(ScopeType.APPLICATION)/@javax.enterprise.context.ApplicationScoped/g
s/@Scope(ScopeType.EVENT)/@javax.enterprise.context.RequestScoped/g
s/@Scope(ScopeType.PAGE)/@org.apache.deltaspike.core.api.scope.ViewAccessScoped/g
s|@Scope(ScopeType.CONVERSATION)|@org.apache.deltaspike.core.api.scope.ViewAccessScoped /* TODO [CDI] check this: migrated from ScopeType.CONVERSATION */|g
s/@Scope(ScopeType.SESSION)/@javax.enterprise.context.SessionScoped/g
s/@Scope(ScopeType.STATELESS)/@javax.enterprise.context.Dependent/g
/import org.jboss.seam.annotations.AutoCreate;\?/d
s/ *@AutoCreate//g
s/org.jboss.seam.annotations.Factory/javax.enterprise.inject.Produces/g
s|@Factory(|@Produces(|g
s/org.jboss.seam.annotations.Out/javax.enterprise.inject.Produces/g
s/@Out/@Produces/g
s/org.jboss.seam.annotations.Create/javax.annotation.PostConstruct/g
s/@Create/@PostConstruct/g
s/org.jboss.seam.annotations.Destroy/javax.annotation.PreDestroy/g
s/@Destroy/@PreDestroy/g
s/@Type(type *= *"text")/@javax.persistence.Lob/g
s|@Startup|/* TODO [CDI] Remove @PostConstruct from startup method and make it accept (@Observes @Initialized ServletContext context) */|g
s/org.zanata.util.Event/javax.enterprise.event.Event/g
s/import org.jboss.seam.annotations.security.Restrict;\?/import org.zanata.security.CheckLoggedIn;\nimport org.zanata.security.CheckPermission;\nimport org.zanata.security.CheckRole;/g
s/@Restrict("#{identity.loggedIn}")/@CheckLoggedIn/g
s/@Restrict("#{s:hasRole('admin')}")/@CheckRole("admin")/g
s/@Restrict("#{s:hasPermission('', '\(.*\)')}")/@CheckPermission("\1")/g
s/@Restrict("#{s:hasPermission(\\'\\', \\'\(.*\)\\')}")/@CheckPermission("\1")/g
s|@Restrict(\(.*\))|@Restrict(\1) /* TODO [CDI] call hasPermission in the method or use @PermissionTarget */|g
s/s:hasPermission/identity.hasPermission/g
EOF

0 comments on commit 47fdf84

Please sign in to comment.